print odd numbers in MARIE assembly language up to user input value -


it homework , i'm stuck here. appreciated.

i'm trying print odd numbers user input value (say 6 or 7). have following code kind of want not exactly.

here code:

org 100  input             /ask input store num         /store input num  load 1 store oddnum      /store 1 odd number output            /print odd number, prints 1  oddloop, load oddnum  /start of loop add 2               /adds 2 in previous odd number value store oddnum          /stores new odd number output                /prints odd number  load num              /loads user input subt oddnum           /input value minus current odd number value  skipcond 000          /skips next line if value negative jump oddloop          /jumps loop  halt                  /end program  zero,   dec 0 one,    dec 1 two,    dec 2 num,    dec 0 oddnum, dec 0 

if user input 7; prints

1 3 5 7 9 

here, expected output 1 3 5 7

if user input 6; prints

1 3 5 7 

here, expected output 1 3 5

change logic of code, there many possible ways, one:

num = input oddnum = 1  while (oddnum <= num) {   output oddnum   oddnum += 2 } 

(oddnum <= num) equal (not(oddnum > num))

so in other words, if (oddnum-num) > 0 true, jump first instruction after loop (exiting it), otherwise loopy loop till looped looblivion...


and why use this 1 logic , not other:

  • notice there's single output point (you have two)
  • it's while(){}, not do {} while(), work "0" input (not displaying anything), or "1" ("2") input displaying "1" (the do {} while() logic 2 outputs display @ least "1 3" every time).

Comments