number reading routine

This commit is contained in:
Jeremy Penner 2019-11-17 19:30:59 -05:00
parent c12c67b556
commit e639d1fd2a
4 changed files with 46 additions and 10 deletions

BIN
asm.img

Binary file not shown.

24
asm.qf
View file

@ -86,25 +86,34 @@ var lblfixup var currlbl
r@ inst-opcount begin dup while 1 - swap , repeat drop r@ inst-opcount begin dup while 1 - swap , repeat drop
r> inst-nextimpl r> swap ! ; r> inst-nextimpl r> swap ! ;
: int &hcd outb! outb! 1 assembled ;
2 inst mov
2 inst movb
OP_IMM OP_REG16 :noname &hb8 op1 + outb! op2 outw! ; ' mov impl
OP_IMM OP_REG8 :noname &hb0 op1 + outb! op2 outb! ; ' movb impl
: :+r anondo >r , OP_REG16 r> does> @ op1 + outb! ; : :+r anondo >r , OP_REG16 r> does> @ op1 + outb! ;
: :+sreg anondo >r , OP_SREG r> does> @ op1 8 * + outb! ; : :+sreg anondo >r , OP_SREG r> does> @ op1 8 * + outb! ;
: modrm ( mod rm reg ) 8 * | swap 64 * | outb! ; : modrm ( mod rm reg ) 8 * | swap 64 * | outb! ;
: int &hcd outb! outb! 1 assembled ;
2 inst mov
OP_IMM OP_REG16 :noname &hb8 op1 + outb! op2 outw! ; ' mov impl
OP_IMM OP_REG8 :noname &hb0 op1 + outb! op2 outb! ; ' mov impl
OP_REG8 OP_REG8 :noname &h88 outb! 3 op1 op2 modrm ; ' mov impl
2 inst add 2 inst add
OP_REG16 OP_REG16 :noname &h01 outb! &h03 op1 op2 modrm ; ' add impl OP_REG16 OP_REG16 :noname &h01 outb! &h03 op1 op2 modrm ; ' add impl
OP_IMM OP_REG8 :noname &h80 outb! 3 op1 0 modrm op2 outb! ; ' add impl OP_IMM OP_REG8 :noname &h80 outb! 3 op1 0 modrm op2 outb! ; ' add impl
2 inst sub
OP_REG16 OP_REG16 :noname &h29 outb! &h03 op1 op2 modrm ; ' sub impl
OP_IMM OP_REG8 :noname &h80 outb! 3 op1 5 modrm op2 outb! ; ' sub impl
2 inst xor 2 inst xor
OP_REG16 OP_REG16 :noname &h31 outb! &h03 op1 op2 modrm ; ' xor impl OP_REG16 OP_REG16 :noname &h31 outb! &h03 op1 op2 modrm ; ' xor impl
2 inst cmp 2 inst cmp
OP_IMM OP_REG16 :noname &h81 outb! 3 op1 0 modrm op2 outw! ; ' cmp impl OP_IMM OP_REG16 :noname &h81 outb! 3 op1 7 modrm op2 outw! ; ' cmp impl
OP_IMM OP_REG8 :noname &h80 outb! 3 op1 7 modrm op2 outb! ; ' cmp impl
1 inst div 1 inst div
OP_REG16 :noname &hf7 outb! &h03 op1 &h06 modrm ; ' div impl OP_REG16 :noname &hf7 outb! &h03 op1 &h06 modrm ; ' div impl
1 inst mul
OP_REG16 :noname &hf7 outb! &h03 op1 &h04 modrm ; ' mul impl
1 inst push 1 inst push
&h06 :+sreg ' push impl &h06 :+sreg ' push impl
@ -136,6 +145,7 @@ OP_REG16 :noname &hff outb! 3 op1 4 modrm ; ' jmp impl
&h7e :jumprel jle &h7e :jumprel jle
&h75 :jumprel jne &h75 :jumprel jne
&h74 :jumprel jz &h74 :jumprel jz
&heb :jumprel jmps
: .EXIT ax &h4c00 | # mov &h21 int ; : .EXIT ax &h4c00 | # mov &h21 int ;
: d" begin in@ dup [ in@ " lit ] != while outb! repeat drop ; : d" begin in@ dup [ in@ " lit ] != while outb! repeat drop ;

32
in.asm
View file

@ -1,7 +1,33 @@
:> end
cs push \ copy code segment to data segment cs push \ copy code segment to data segment
ds pop ds pop
ax 0 # mov \ read number
\ clobbers: ax, bx, cx, dx
dx dx xor
cx cx xor
bx 10 # mov
dx push
:> readnext
ax &h0100 # mov
&h21 int
:> readover
al in@ 0 # cmp
readover jl
al in@ 9 # cmp
readover jg
cl al mov
cl in@ 0 # sub
ax pop
bx mul
ax cx add
ax push
readnext jmps
readover <:
ax pop
\ ax 0 # mov
\ print number \ print number
\ in: ax = number \ in: ax = number
\ clobbers: ax, bx, cx, dx \ clobbers: ax, bx, cx, dx
@ -18,7 +44,7 @@
:> moredigits :> moredigits
dx pop dx pop
dl 48 # add dl in@ 0 # add
ax &h0200 # mov ax &h0200 # mov
&h21 int &h21 int
bx dec bx dec
@ -26,4 +52,4 @@
0 .EXIT 0 .EXIT
cx 11 # mov end <:

BIN
out.com

Binary file not shown.