Translate the following C program into an assembly program. The C program finds the minimal value of three signed integers. Assume a, b, and c is stored in register r0, r1, and r3, respectively. The result min is saved in register r4.

If (a< b && a min =a;
} else if (b min=b;
} else {
Min=c:
}

Respuesta :

Answer:

  GLOBAL minRoutine

  AREA MYCODE, CODE, READONLY

  ENTRY

minRoutine

  MOV r0, #0xA  

  MOV r1, #0x3  

  MOV r3, #0x8  

  CMP r0,r1      

  BLT less1Routine      

  CMP r1,r0    

  BLT less2Routine      

  MOV r4,r3      

less1Routine              

CMP r0,r3      

  BLT cond1

less2Routine              

  CMP r1,r3    

  BLT cond2

 

cond1              

  MOV r4,r0      

cond2            

  MOV r4,r1      

  END

Explanation:

  • Inside the minRoutine, move the essential values to the r0, r1 and r3 registers.
  • Check if a is greater than b by comparing value in r0 with r1.
  • Jump to less1Routine, if value of r0 is less than value of r1. Otherwise go to next instruction .
  • Check if b is greater than a by comparing value in r1 with r0.
  • Jump to less2Routine, if value of r1 is less than value of r0. Otherwise go to next instruction .
  • Finally move result of r1 into r4 register.
ACCESS MORE