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 4:

Assume R1 is set to an input value at the start. Print R1 only if it's an even number. (Note: R1 might be positive or negative!)

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