Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @5
- D=A //D=5
- @i
- M=D
- (LOOP)
- @i
- D=M
- @END
- D;JEQ
- @sum
- M=D+M
- @i
- M=M-1
- @LOOP
- 0;JMP
- (END)
- @END
- 0;JMP
- ------------------------
- // Write the pseudocode for the algorithm on the left (Add 5+...+1). Generally it compute the sum of a number from the upper bound (5) to the lower bound (1)
- Declare and initialize counter i
- Declare and initialize sum
- Loop
- Load memory location i
- Assign value in I to Data
- Load memory location END
- If Data is 0 then Jump to location END; if not continue next intr
- Load memory location sum
- Add data (current value of i) to sum (memory of sum)
- Load memory location i
- Decrease I by 1
- Load memory location LOOP
- Jump to LOOP to execute next round
- END
- Load memory location END
- Jump until halt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement