dimanche 5 décembre 2021

how to translate an if condition to marie's assembly?

I am being asked to write a code that multiply 2 inputs from the user in Marie's assembly . I did everything right except that in the question there is a condition in pseudocode that I cannot quite imply in my code .. if x =0 then x=x+3 which means if the first input is zero I need to increment x by 3 . my original multiplication code works and this is it:

ORG 512
Input
Store x
Input
Store y
loop,Load z
 Add x
 Store z
 Load y
 Subt one
 Store y
 Skipcond 400
 Jump loop
Load z
Output
Halt
x, DEC 0
y, DEC 0
one, DEC 1
z, DEC 0

this code works for any x or y to multiply yet I cannot implement the condition above even though I tried this

ORG 512
Input
Store x
Skipcond 800   /in case of input x to 0
Add one    /adding one to x to reach 1
Add one     /adding one to x to reach 2
Add one      /adding one to x to reach 3
Store x
Input
Store y
loop,Load z
   Add x
   Store z
   Load y
   Subt one
   Store y
   Skipcond 400
   Jump loop
Load z
Output
Halt
x, DEC 0
y, DEC 0
one, DEC 1
z, DEC 0

but this messes up when I put both x and y as positives and it gives strange answer to multiplication .

Aucun commentaire:

Enregistrer un commentaire