rr h
rr l
push hl
- jr next1
+ jp next1 ;jr next1
;
code sp@ ( -- x )
pop bc ; pop u1
pop hl ; pop ud hi
pop de ; pop ud lo
+ push hl
+ call print_hexw
+ ld l,e
+ ld h,d
+ call print_hexw
+ ld a,0x2f
+ call print_char
+ ld l,c
+ ld h,b
+ call print_hexw
+ pop hl
ld a,16
or a
ex de,hl
adc hl,hl
ex de,hl
- adc hl,hl ; can't overflow, leaves cf = 0
+ adc hl,hl
+ jr nc,udiv_test
+ ; shift left has overflowed, so we can always subtract bc, and
+ ; always cf=1 to indicate subtraction went, record cf in quotient
+ sbc hl,bc
+ jr udiv_cont
+udiv_test:
+ ; shift left has not overflowed, see if we can subtract bc, cf=0
+ ; indicates subtraction went, record complement of cf in quotient
sbc hl,bc
- jr nc,udiv_skip
+ jr nc,udiv_goes
add hl,bc
-udiv_skip:
+udiv_goes:
+ ccf
+udiv_cont:
dec a
jr nz,udiv_loop
ex de,hl
- adc hl,hl
+ adc hl,hl ; record final quotient bit
+ ld a,0x3d
+ call print_char
+ push hl
+ call print_hexw
+ ld a,0x72
+ call print_char
+ ld l,e
+ ld h,d
+ call print_hexw
+ pop hl
+ ld a,0xa
+ call print_char
push de ; push u2 (remainder)
push hl ; push u1 (quotient)
-
+
exx
jr next1
;
ld h,a
inc bc
jp (hl)
+
+print_hexw:
+ ld a,h
+ call print_hexb
+ ld a,l
+print_hexb:
+ push af
+ rrca
+ rrca
+ rrca
+ rrca
+ call print_hexn
+ pop af
+print_hexn:
+ and 0xf
+ add a,0x30
+ cp 0x3a
+ jr c,print_char
+ add a,0x41 - 0x3a
+print_char:
+ out (STDOUT_PORT),a
+ ret
;
: negate ( n1 -- n2 )
t{ 21845 dup xor -> 0 }t \ $5555
t{ 21845 dup 2* xor -> 65535 }t
-t{ -2147483648 2147483647 < -> -1 }t \ 32bit $80000000 $7FFFFFFF
-t{ -2147483648 0 < -> -1 }t \ 32bit $80000000 0
-t{ 0 -2147483648 < -> 0 }t \ 32bit 0 $80000000
+t{ -32768 32767 < -> -1 }t \ 16bit $8000 $7FFF
+t{ -32768 0 < -> -1 }t \ 16bit $8000 0
+t{ 0 -32768 < -> 0 }t \ 16bit 0 $8000
\ both positive
t{ 10 10 < -> 0 }t
case STDOUT_PORT:
stdio_service(1, STDIO_BUFFER_SIZE);
stdio_buffer_write(&stdout_buffer, data);
+ stdio_service(1, 1);
break;
case STDERR_PORT:
stdio_service(1, STDIO_BUFFER_SIZE);