Advertisement
Guest User

Lman

a guest
Jun 1st, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Dividing numbers
  2. ; This program inputs two numbers,
  3. ; divides the first by the second, and
  4. ; outputs the quotient.
  5. ; Preconditions:
  6. ;   0 <= first number <= 999
  7. ;   0 < second number <= 999
  8.  
  9. ;;; input two numbers
  10. 00 inp     ; input first number
  11. 01 sta 20  ; store number to mailbox 20
  12. 02 inp     ; input second number
  13. 03 sta 21  ; store number to mailbox 21
  14. ;;; subtract second from first
  15. 04 lda 20  ; load current first number
  16. 05 sub 21  ; subtract second from first
  17. 06 sta 20  ; store new first number
  18. ;;; go to increment quotient if >= 0
  19. 07 brp 09  ; go to increment quotient
  20. 08 bra 13  ; complete division as < 0
  21. ;;; increment quotient
  22. 09 lda 23  ; load quotient
  23. 10 add 22  ; add 1 to quotient
  24. 11 sta 23  ; store new quotient
  25. 12 bra 04  ; go to subtract second again
  26. ;;; output quotient
  27. 13 lda 23  ; load quotient
  28. 14 out     ; output quotient
  29. 15 hlt     ; end of program
  30. ;;; data and constant value
  31. 20 dat     ; first number
  32. 21 dat     ; second number
  33. 22 dat 1   ; constant 1
  34. 23 dat 0   ; quotient
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement