99 Bottles of Beer/Assembly: Difference between revisions

Content added Content deleted
(Add 8080 assembly version)
Line 425: Line 425:
j0F00</lang>
j0F00</lang>



=={{header|8080 Assembly}}==
<lang 8080asm>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 99 bottles of beer, in 8080 assembly ;;
;; Written to run under CP/M ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

bdos: equ 5
char: equ 2


org 100h

mvi b,100

verse: call beer ; _ bottles of beer
call bputs ; on the wall
push h
call bputs ; , \r\n
call beer ; _ bottles of beer
pop h
call bputs ; , \r\n
;; Last verse?
dcr b
jz final
;; No - take one down
lxi h,stake
call bputs
;; Decrement number
lxi h,snum + 1
dcr m
mvi a,'0' - 1
cmp m
jnz lstlin
mvi m,'9'
dcx h
dcr m

lstlin: call last
jmp verse

;; Go to the store and buy some more
final: lxi h,sstore
call bputs
lxi h,3939h
shld snum
call last
rst 0

;; Output "_ bottle(s) of beer on the wall.\r\n"
last: call beer
call bputs
lxi h,sdot
jmp bputs
;; Output "_ bottle(s) of beer"
beer: call numout ;N
lxi h,sbotl
call bputs ;bottle
mvi a,2
cmp b
jnz bputs
inr l
jmp bputs
;; Output number, or "no more"
numout: lxi h,snum
mvi a,'0'
cmp m
jnz bputs
inx h
cmp m
jnz bputs
lxi h,sgone
;; Output zero-terminated string
;; and leave HL set to next string
bputs: xra a
ora m
inx h
rz
push b
push h
mvi c,char
mov e,a
call 5
pop h
pop b
jmp bputs
;; Strings
snum: db '99',0
sbotl: db ' bottle',0
sbeer: db 's of beer',0
swall: db ' on the wall',0
scomma: db ',',13,10,0
sdot: db '.',13,10,13,10,0
sgone: db 'No more',0
stake: db 'Take one down and pass it around',13,10,0
sstore: db 'Go to the store and buy some more,',13,10,0

</lang>
=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
<!-- printf missing ? --->
<!-- printf missing ? --->