Question

What are the values of the registers, as decimal integers, after executing the following code? mov...

What are the values of the registers, as decimal integers, after executing the following code?

        mov   r0, #9
        mov   r1, #1
    top:
        cmp   r0, #0
        beq   finish
        lsl   r1, r1, #1
        sub   r0, r0, #1
        b     top
    finish:
        mov   r2, #47
    

R0:  R1:  R2:  R3:

Homework Answers

Answer #1

Answer is as follows :

mov r0, #9 // move data 9 to register r0. So r0 contains 9

mov r1, #1 // move data 1 to register r1. So r1 contains 1

top:

cmp r0, #0 // Compare value of r0 with 0 i.e. 9 with 0 (not equal)

beq finish //if both values are equal, than jump to label finish. Both are not equal

lsl r1, r1, #1 // logical shift the contents of r1 i.e. 1 in decimal or 0001 in binary after performing shift left we get 0010 i.e. 2. So r1 contains 2 now

sub r0, r0, #1 // perform r0 = r0-1 i.e. r0 = 9-1 = 8

b top // branch to top

finish:

mov r2, #47

So at first r0 = 8 , r1 = 2

Again branch to label top when r0= 8:

Both values are not equal again, so perform the operations.

lsl r1, r1, #1 // logical shift the contents of r1 i.e. 2 in decimal or 0010 in binary after performing shift left we get 0100 i.e. 4. So r1 contains 4 now

sub r0, r0, #1 // perform r0 = r0-1 i.e. r0 = 8-1 = 7

b top // branch to top

So now r0 = 7 , r1 = 4

By doing these calculations

we get when r0 = 7 ,

r1 = 1000 (after shifting) i.e. 8, r0 = 6

we get when r0 = 6

r1 = 10000 (after shifting) i.e. 16, r0 = 5

we get when r0 = 5

r1 = 100000 (after shifting) i.e. 32, r0 = 4

we get when r0 = 4

r1 = 1000000 (after shifting) i.e. 64, r0 = 3

we get when r0 = 3

r1 = 10000000 (after shifting) i.e. 128, r0 = 2

we get when r0 = 2

r1 = 100000000 (after shifting) i.e. 257, r0 = 1

we get when r0 = 1

r1 = 1000000000 (after shifting) i.e. 513, r0 = 0

we get when r0 = 0

So values get equal and control jumps to label finish

finish:

mov r2, #47 //move data 47 to register r2. So r2 contains 47.

SO AT LAST WE GET :

r0 = 0 , r1 = 513 , r2 = 47

There is no update in register r3. So it contains default value

All the registers are assumed to be 16 bit.

if there is any query please ask in comments..

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following code runs on a microprocessor with five pipelined stages. In the code lw is...
The following code runs on a microprocessor with five pipelined stages. In the code lw is a load word and sw is a store word. The register on the far right is the target register for lw and add and source for sw. The memory latency is 2 cycles. lw 0(r1),r2 label1:    beq r2,r0,label2 # not taken once, then taken lw 0(r2),r3 beq r3,r0,label1 # taken add r1,r3,r1 label2: sw 0(r2),r1 Identify all the possible hazards that may exist in...
III. After execution of the following instructions what value will be in register r0? LDR                ...
III. After execution of the following instructions what value will be in register r0? LDR                 r12, =0xA4000000 LDR                 r0, =0x75 LDR                 r1, =0xD2 LDR                 r2, =0x9C LDR                 r5, =0xC STMDB           r12!, {r0-r2, r5} LDR                 r0, [r12, #8] SUB                 r0, #0x77 IV. Assume that the variables f, g, h, i, and j are assigned to registers r0, r1, r2, r3, and r4, respectively. Assume that the base address of the arrays A and...
IV.Translate the following C code fragment to ARM assembly instructions. Assume t, x, y, and z...
IV.Translate the following C code fragment to ARM assembly instructions. Assume t, x, y, and z are stored in registers r0, r1, r2, and r3. unsigned int x, y, z, t; do { x = x + 1; z = t + (z << 1); y = y - x; } while (y != x); V. What does the following sequence of instructions do? Why? RSB r2, r3, r3, LSL #4 RSB r2, r2, r2, LSL #3 VI. Write a...
I. What value will be in register r2 after execution of the following instructions? Show your...
I. What value will be in register r2 after execution of the following instructions? Show your work with the register values after executing each instruction. MOV r2, #0x0 LDR r1, =0xCF MOVS r1, r1, LSR #1 ADC r2, r2, #0 MOVS r1, r1, LSR #1 ADC r2, r2, #0 II. Assume a 32 bit register holds a data of four bytes as B3B2B1B0. Write a sequence of ARM instruction that takes this data as input and swaps the bytes 0...
After running the program below, what will be the values in registers EAX and EBX? mov...
After running the program below, what will be the values in registers EAX and EBX? mov EAX,0123ABCDh       mov EBX,4455AABBh       PUSH BX       PUSH AX       POP AX       POP BX Question 2 options: EAX=ABCD 0123 EBX=AABB4455 EAX= ABCD0123 EBX=4455AABB EAX=0123ABCD   EBX=4455AABB EAX=ABCD0123    EBX=AABB4455
VII. After execution of the following instructions what value will be in register r2? Trace the...
VII. After execution of the following instructions what value will be in register r2? Trace the program and write the value of the registers at each line to receive full credit. LDR r12, =0xA4000000 LDR r0, =0x2D STR r0, [r12, #-4]! LDR r0, =0x5E STR r0, [r12, #-4]! LDR r0, =0xD5 STR r0, [r12, #-4]! LDMIA r12!, {r0-r2} SUB r2, #0x68 VIII. Write a simple ARM assembly program to divide a 32 bit positive number stored in r0 by a...
Consider a program having following sequence of instructions, where the syntax consists of an opcode followed...
Consider a program having following sequence of instructions, where the syntax consists of an opcode followed by the destination register followed by one or two source registers: Instruction no Instructions 1 ADD R3, R1, R2 2 LOAD R6, [R3] 3 AND R7, R5, 3 4 ADD R1, R6, R0 5 SUB R2, R1, R6 6 AND R3, R7, 15 7 SUB R5, R3, R4 8 ADD R0, R1, R10 9 LOAD R6, [R5] 10 SRL R7, R0, 8 Assume the...
After the following MASM code is executed: MOV EAX, 212 MOV EBX, 19 CDQ DIV EBX...
After the following MASM code is executed: MOV EAX, 212 MOV EBX, 19 CDQ DIV EBX What is the value in the EAX register (in decimal)? What is the value in the EBX register (in decimal)? What is the value in the EDX register (in decimal)?
Consider executing the following code on the pipelined datapath that we discussed in class. a). During...
Consider executing the following code on the pipelined datapath that we discussed in class. a). During the 5th cycle, which registers are being read and which register(s) will be written (using the register file)? b). Explain what the forwarding unit is doing during the 5th cycle of execution. Which registers are being compared? List all pairs of registers that are compared during the 5th cycle for the forwarding unit. (First, you need to determine which instruction's values are in the...
PLEASE EXPLAIN EACH LINE OF CODE ONLY. USE COMMENTS NEXT TO EACH LINE TO EXPLAIN WHAT...
PLEASE EXPLAIN EACH LINE OF CODE ONLY. USE COMMENTS NEXT TO EACH LINE TO EXPLAIN WHAT EACH IS CODE IS DOING THANKS. PLEASE COPY PASTE AFTER YOURE DONE NOT SCREENSHOT BECAUSE I NEED TO BE ABLE TO EDIT IT THANKS. // MODULE B: Method 2: Embedding an in-line asssembly language module in a C progrmming #include "stdafx.h" #include "stdio.h" #include<iostream> int main () { printf(" Lab_No_01_Getting_Stated_into_x86_Assembly_from_a_C++_program\n"); // Lab number and title here printf(" Module B: Embedding an in-line asssembly language...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT