Skip to content

Commit

Permalink
have octal and hexidecimal working now
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Goehrig committed Jul 15, 2012
1 parent 7ce619d commit d34e42f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 113 deletions.
19 changes: 10 additions & 9 deletions system.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

; key --
%macro type 0
dupe
stack ; nos address
arg2
literal 1 ; stdout
arg1
literal 1 ; 1 byte
arg3
literal write
os
dupe ; key -- key key
stack ; nos address key -- key stack
arg2 ; key stack -- key
literal 1 ; key -- key stdout
arg1 ; key -- key
literal 1 ; key -- key 1 byte
arg3 ; key 1 -- key
literal write ; key -- key write
os ; key -- key count
drop ; key -- key
drop
%endmacro

Expand Down
144 changes: 90 additions & 54 deletions term.asm
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,53 @@ call term
term:
key
call test_quit
method done
if
drop
call test_retn
dupe
type
call space
dupe
call octal
call space
call hexen
call space
jmp term

test_quit:
literal 17
equals
method done
if
ret

test_retn:
literal 13
equals
method nl
if
ret

done:
offset done_str ; done_str -> tos
source ; tos <-> src
fetchplus
fetch ; [done_str] -> tos
dupe
type
fetchplus
shiftrnum 8
dupe
type
fetchplus
shiftrnum 8
dupe
type
fetchplus
shiftrnum 8 ; don't dupe after so type consumes
type
call eol
quit
ret

nl:
literal 0xa
type
ret

eol:
literal 0xd
type
Expand All @@ -55,57 +76,72 @@ clear:
type
ret

emit:
mov r11,10 ; radix
mov rcx,20
.emit:
xor rdx,rdx ; make sure we don't get junk
idiv r11 ; divide by radix
add dl,48 ; add ascii 0
mov byte [ r13 + number + rcx - 1 ],dl ; move to slot
test rax,rax ; if we've run out of data
jz .done ; quit
loopnz .emit ; otherwise do next loop
.done:
literal 20
offset number
show ; null characters don't write!!!!
octal:
dupe ; a -- a a
shiftrnum 3 ; a a -- a a/8
dupe ; a -- a a/8 a/8
shiftrnum 3 ; a -- a a/8 a/16
andnum 7 ;
addnum 48 ;
type ; a/16&7
andnum 7 ;
addnum 48 ;
type ; a/8&7
andnum 7 ;
addnum 48 ;
type ; a&7
ret

hexen:
mov r11,16
mov rcx,16
.hexen:
xor rdx,rdx
idiv r11
cmp rdx,10
jl .lessthanten
add rdx,39
.lessthanten:
add rdx,48
mov byte [ r13 + number + rcx - 1],dl
test rcx,rcx
loopnz .hexen
.done:
literal 20
offset number
show
dupe
shiftrnum 4 ; a - a a/16
andnum 15 ; a - a a/16&15
literal 9 ; a - a a/16&15 9
more ; a - a a/16&15 flag
method first_digit ; a - a a/16&15 flag digit
if ; a - a a/16&15
hexen_cont:
addnum 48 ; "a"-10
type
andnum 15
literal 9
more
method second_digit
if
addnum 48
type
ret

first_digit:
addnum 39
method hexen_cont
invoke

second_digit:
addnum 87
type
ret


; ANSI color codes and jazz
align 16
align 8
terminal_data:
number: dq 0,0,0
tibcnt: dq 0
tibbuf: dq 0,0,0,0,0
done_str: dq "d","o","n","e"
plain: db 27,"[0;0;0m"
red: db 27,"[0;31;40m"
green: db 27,"[0;32;40m"
yellow: db 27,"[0;33;40m"
blue: db 27,"[0;34;40m"
magenta: db 27,"[0;35;40m"
cyan: db 27,"[0;36;40m"
white: db 27,"[0;37;40m"
position: db 27,"[6n"
done_str: db "done",0,0,0,0
align 8
plain_str: db 27,"[0;0;0m"
align 8
red_str: db 27,"[0;31;40m"
align 8
green_str: db 27,"[0;32;40m"
align 8
yellow_str: db 27,"[0;33;40m"
align 8
blue_str: db 27,"[0;34;40m"
align 8
magenta_str: db 27,"[0;35;40m"
align 8
cyan_str: db 27,"[0;36;40m"
align 8
white_str: db 27,"[0;37;40m"
align 8
position_str: db 27,"[6n"
37 changes: 0 additions & 37 deletions tools.asm

This file was deleted.

29 changes: 16 additions & 13 deletions vm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ rstack equ 8*18 ;

; Logic Macros

%macro intersect 0 ; binary and tos and nos
%macro andb 0 ; binary and tos and nos
and tos,[nos]
nip
%endmacro
Expand All @@ -340,7 +340,7 @@ rstack equ 8*18 ;
and tos,%1
%endmacro

%macro union 0 ; binary or tos with nos
%macro orb 0 ; binary or tos with nos
or tos,[nos]
nip
%endmacro
Expand All @@ -349,7 +349,7 @@ rstack equ 8*18 ;
or tos,%1
%endmacro

%macro exclusion 0 ; binary xor tos with now
%macro xorb 0 ; binary xor tos with now
xor tos,[nos]
nip
%endmacro
Expand All @@ -358,7 +358,7 @@ rstack equ 8*18 ;
xor tos,%1
%endmacro

%macro compliment 0 ; ones compliment negation
%macro notb 0 ; ones compliment negation
not tos
%endmacro

Expand Down Expand Up @@ -389,31 +389,34 @@ rstack equ 8*18 ;

; b a -- b 0|a
%macro less 0
cmp rax,[nos]
jl .cont
cmp [nos],rax
jl .lcont
xor rax,rax
.cont: nop
.lcont: nop
%endmacro

; b a -- b 0|a
%macro more 0
cmp rax,[nos]
jg .cont
cmp [nos],rax
jg .gcont
xor rax,rax
.cont: nop
.gcont: nop
%endmacro

; x addr -- x --> addr
%macro if 0
rpush
test rax,rax ; if it is zero we don't jump
jz .cont
jz .ifcnt
drop
ret
.cont: pop tmp1 ; discard return address on return stack
.ifcnt: pop tos ; discard return address on return stack
drop
%endmacro

%macro invoke 0

rpush
ret
%endmacro


0 comments on commit d34e42f

Please sign in to comment.