Saturday 28 November 2015

ARM Assembly Language Programs

Microcontroller & Embedded Systems

1. Write ARM assembly language program to find largest/smallest value from given two numbers.
    
        AREA    bigger, CODE, READONLY
ENTRY
MAIN
        LDR    R1, Value1        ;load first value to be compared
        LDR    R2, Value2        ;load second value to be compared
       
        CMP    R1, R2             ;compare them
        BHI    DONE               ;if R1 contains the highest
       
        MOV R1, R2                ;otherwise overwrite R1
       
DONE
        STR    R1, Result            ;store the result
        SWI    &11
       
Value1    DCD    &12345678        ;value to be compared
Value2    DCD    &87654321        ;value to be compared
Result    DCD    0                          ;space to store result
        END


2. Write ARM assembly language program to find average of two numbers.

             AREA    Average, CODE, READONLY                    ; name code block
             ENTRY                                             ; marker of first executable instruction
start             
             ADR    r1, FIRSTNUM                                ; load first address into r1
             ADR    r2, SECONDNUM                                ; load second address into r2
             ADR    r3, AVGRESULT                                ; load result address into r3
             LDR    r4, [r1]                                    ; load first number into r4
             LDR    r5, [r2]                                    ; load second number into r5
             ADD    r0, r4, r5                                    ; add numbers together
             MOV    r0, r0, ASR#1                                ; divide by two using arithmetic shift
             STR    r0, [r3]                                    ; store result to address pointed to by r3
                      
             SWI    0x11                                        ; terminate the program
            
FIRSTNUM    DCD    &20
SECONDNUM    DCD    &50
AVGRESULT    DCD    &0           
            END                                                 ; marks the end of the file

ARM Assembly Language Programs

Microcontroller & Embedded Systems

1. Write ARM assembly language program to display "Hello World"

        AREA      HelloW, CODE, READONLY
SWI_WriteC        EQU  &0   
SWI_Exit         EQU  &11   
        ENTRY   
 

START     ADR        R1, TEXT   
LOOP     LDRB    R0, [R1], #1
       

        CMP      R0, #0
        SWINE    SWI_WriteC   
        BNE        LOOP
        SWI        SWI_Exit    
       
TEXT    =        "HELLO WORLD", &0a, &0d, 0
        END


2. Write ARM assembly language program to find the one's complement (inverse) of a number.

        AREA    Program, CODE, READONLY
        ENTRY

Main
        LDR     R1, Value                        ; Load the number to be complemented
        MVN     R1, R1                          ; take 1's complement of R1
        STR     R1, Result                        ; Store the result
        SWI     &11

Value   DCD     &FF                            ; Value to be complemented
Result  DCD     &ABCD1234              ; Storage for result

        END



3. Write an assembly language program to compute 4x2 +3x... ... if x is stored in r1. Store the result in r0.

                AREA    equation, CODE, READONLY
                ENTRY

start
                MUL r0, r1, r1                     ; result <-- x * x
                LDR r2, =4                         ; tmp <-- 4
                MUL r0, r2, r0                     ; result <-- 4 * x * x
                LDR r2, =3                         ; tmp <-- 3
                MUL r2, r1, r2                     ; tmp <-- x * tmp
                ADD r0, r0, r2                     ; result <-- result + tmp
stop          B     stop
                end   

ARM Assembly Language Program to add / sub / mul two 32 / 64 bit numbers.

Microcontroller & Embedded Systems

1. Write ARM assembly language program to add two 32 bit numbers.


        AREA    add32, CODE, READONLY
ENTRY
MAIN
        LDR    R0, =Value1
        LDR    R1, [R0]
           
        ADD    R0, R0, #0*4
           
        LDR    R2, [R0]
           
        ADD R1, R1, R2
           
        LDR    R0, =Result
           
        STR    R1, [R0]
           
        SWI    &11
           
Value1    DCD    &37E3C123
Value2    DCD    &367402AA
           
Result    DCD    0


2. Write ARM assembly language program to add two 64 bit numbers.
     
        AREA    add64, CODE, READONLY
ENTRY
MAIN
        LDR    R0, =Value1        ;pointer to first value
        LDR    R1, [R0]            ;load first part of value1
        LDR    R2, [R0, #4]        ; load lower part of value1
        LDR    R0, =Value2        ;pointer to second  value
        LDR    R3, [R0]            ;load upper part of value2
        LDR    R4, [R0, #4]        ; load lower part of value2
      
        ADDS    R6, R2, R4        ;add lower 4 bytes  and set carry flag
        ADC    R5, R1, R3        ;add upper 4 bytes  including carry
      
        LDR    R0, =Result        ;pointer to result
      
        STR    R5, [R0]            ;store upper part of result
        STR    R6, [R0, #4]        ;store lower part of result
      
        SWI    &11
      
Value1    DCD    &12A2E640, &F2100123
Value2    DCD    &001019BF, &40023F51
Result    DCD    0
      
        END

Friday 20 November 2015

University Question Paper Analysis

University Question Paper Analysis

Microcontroller & Embedded Systems

Following table shows Marks allotted to each chapter for MES subject (weightage of chapter) in University Examinations.


Chapter No
Marks of Questions (120 Marks)
Dec 2014
Marks of Questions
(120 Marks)
May 2015
1
5
5
2
24
25
3
25
24
4
26
16
5
28
38
6
12
12