1. Engineering
  2. Computer Science
  3. write assembly programs to carry out the following operations problem...

Question: write assembly programs to carry out the following operations problem...

Question details

Write assembly programs to carry out the following operations.

Problem 5:

Assume R1 and R2 are both set to positive input values at the start. Print the result of dividing R1 by R2 in quotient/remainder form. For example, if R1=9 and R2=2, you should print 4 1; if R1=9 and R2=3, you should print 3 0.

You can only use instruction below:

Instructions available: LOAD integer, destination register Loads an integer into a register. Example LOAD 5, R2 sets R2 to 5 ADD source register, destination register Adds the integer in the source register to the one in the destination register, storing the result in the destination register. Example: ADD R1, R2 MOV source register, destination register sets R2 to R1+R2 Moves the value in the source register to the destination register (source register is left unchanged, so you can also think of this as copy) Example MOV R1, R2 sets R2 to R1 NEG register Negate the value in a register.

Example: NEG R1 sets R1 to -R1 JMP label Unconditional jump to the line with the given label Example loop: ADD R1, R2 JMP loop jump to the previous line, which is labeled loop JZ register, label JNZ register, label JLZ register, label JGZ register, label Conditional jumps. JZ jumps to label if register is zero. JNZ jumps if register is non-zero. JLZ jumps if register is less than zero. JGZ jumps if register is greater than zero. PRINT register Print the value in register. In a real CPU, there wouldnt normally be a low-level instruction to print out numbers, but for our purposes it lets you write assembly programs that output results. Example: PRINT RI i prints the value in R1

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution