35 lines
1.7 KiB
Plaintext
35 lines
1.7 KiB
Plaintext
ORG 0100H
|
|
BITS EQU 128 ; 128 bits of precision
|
|
BYTES EQU BITS / 8 ; Number of bytes we store those bits in
|
|
|
|
; Zero out the storage for our number
|
|
LXI H,BUFR ; HL points at BUFR. (HL is idiomatically used for pointers)
|
|
MVI C,BYTES ; C holds the number of bytes we'll use
|
|
XRA A ; XOR with A is a 1-byte instruction to set A to zero
|
|
INIT: MOV M,A ; Store 0 to address pointed to by HL
|
|
INX H ; Advance HL to the next byte
|
|
DCR C ; Count down
|
|
JNZ INIT ; Keep looping if we're not done
|
|
|
|
; The "very long integer" is zeroed, so start the loop
|
|
LOOP: CALL PRBUFR ; Output our number
|
|
LXI H,BUFR ; HL Points to BUFR
|
|
MVI C,BYTES ; Count down (assume fewer than 256 bytes in our integer)
|
|
NEXT: INR M ; Increment the byte pointed to by HL. Sets the zero flag
|
|
JNZ LOOP ; If the increment didn't overflow A, start the loop over
|
|
; This byte overflowed, so we need to advance to the next byte in our number
|
|
INX H ; We store our byes in order of increasing significance
|
|
DCR C ; Count down to make sure we don't overflow our buffer
|
|
JNZ NEXT ; jump to process the next, more significant byte
|
|
|
|
; If we get here, we have overflowed our integer!
|
|
HALT ; TODO: probably something other than "halt the CPU"
|
|
|
|
PRBUFR: ; TODO, a subroutine that shows all of the digits in BUFR on the console
|
|
; Assume that this code trashes all our registers...
|
|
RET
|
|
|
|
BUFR: ; This space will hold our number
|
|
; We zero this memory before the loop
|
|
END
|