Z80 – Binärumrechnung
Der folgende Code rechnet eine bis zu 16 Bit große Zahl in eine Binärzahl um und gibt diese aus. Die Ausgaberoutine ist nicht Teil des Codeschnipsels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
; HL enthält die bis zu 16 Bit große Zahl ; Hier am Beispiel der Zahl 500 ld hl,500 call binary halt ; Convert to binary ; The OUT(0x0A),A command does the output to an device binary: push hl push bc ld c,0x00 call gobin ld h,l call gobin pop bc pop hl ret gobin: ld b,0x08 bitloop: ld a,h bit 7,h jr nz,one zero: ld a,c or a jr z,end1 ld a,"0" out (0x0a),a jr end1 one: ld a,"1" ld c,0x01 out (0x0a),a end1: ld a,h rlca ld h,a djnz bitloop ret |