Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Dividing numbers
- ; This program inputs two numbers,
- ; divides the first by the second, and
- ; outputs the quotient.
- ; Preconditions:
- ; 0 <= first number <= 999
- ; 0 < second number <= 999
- ;;; input two numbers
- 00 inp ; input first number
- 01 sta 20 ; store number to mailbox 20
- 02 inp ; input second number
- 03 sta 21 ; store number to mailbox 21
- ;;; subtract second from first
- 04 lda 20 ; load current first number
- 05 sub 21 ; subtract second from first
- 06 sta 20 ; store new first number
- ;;; go to increment quotient if >= 0
- 07 brp 09 ; go to increment quotient
- 08 bra 13 ; complete division as < 0
- ;;; increment quotient
- 09 lda 23 ; load quotient
- 10 add 22 ; add 1 to quotient
- 11 sta 23 ; store new quotient
- 12 bra 04 ; go to subtract second again
- ;;; output quotient
- 13 lda 23 ; load quotient
- 14 out ; output quotient
- 15 hlt ; end of program
- ;;; data and constant value
- 20 dat ; first number
- 21 dat ; second number
- 22 dat 1 ; constant 1
- 23 dat 0 ; quotient
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement