Question: HACK ASSEMBLY LANGUAGE This asm computes the modulo of two numbers Assuming R0 stores the number a and R1 stores the number b (b can

HACK ASSEMBLY LANGUAGE

This asm computes the modulo of two numbers Assuming R0 stores the number a and R1 stores the number b (b can not be 0) so in normal programming language, the goal is to compute RAM[R0]%RAM[R1] The result will be put to RAM[R2] Assuming RAM[R1] is positive integer and RAM[R0] is non-negative integer

This is what I have. What is wrong??

// Storing the value in R0 into variable a

@0 D=M // load RAM[0] into D (Sub) @1 D=D-M // D=D-RAM[1] (i.e., D=RAM[0]-RAM[1]) @Save D;JLT // jump to Save label if D < 0 (RAM[0]-RAM[1]<0) @Sub 0;JMP // otherwise (else), jump back to top Sub label (subtract again) (Save) @2 D=D+M // save operation involves saving D into RAM[0] @0 // but we gotta add back RAM[1] because D<0 currently m=D (end) @end>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!