Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q7: you have two 32-bit numbers stored at memory locations 0x20000004 and 0x2000

ID: 3803854 • Letter: Q

Question

Q7: you have two 32-bit numbers stored at memory locations 0x20000004 and 0x20000008, write an assembly program to compare these two numbers and calculate how many bit positions at which these two numbers have the same content.

Q12: For the following assembly code, how many times the loop ‘calculate’ is going to be executed? Why?

   MOV r1, 10         

calculate SUB r1, r1, 1                         

                  BNE calculate

Q13: The following code is called ‘delay loop’, It is used to create a certain delay during program execution. Calculate the amount of delay created by this code:                     

               LDR r0,= #9800

repeat     SUBS r0,r0,#1              

   BNE repeat

Given that the clock frequency of the processor is 48 MHz and the execution time of the LDR instruction is 2 clock cycles, SUBS instruction is 1 clock cycle, BNE instruction 2 clock cycle when branch taken and 1 clock cycle when branch is not taken.

Explanation / Answer

MVI B, 09 :"Initialize counter"   
START :"LXI H, 2200H: Initialize memory pointer"
MVI C, 09H :"Initialize counter 2"
BACK: MOV A, M :"Get the number"
INX H :"Increment memory pointer"
CMP M :"Compare number with next number"
JC SKIP :"If less, don’t interchange"
JZ SKIP :"If equal, don’t interchange"
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H :"Interchange two numbers"
SKIP:DCR C :"Decrement counter 2"
JNZ BACK :"If not zero, repeat"
DCR B :"Decrement counter 1"
JNZ START
HLT :"Terminate program execution"