mirror of
https://github.com/samsonjs/sectorlisp.git
synced 2026-04-27 14:57:41 +00:00
Shave twelve bytes (now 458 bytes)
This commit is contained in:
parent
5a33a6b97a
commit
d587ce19d1
1 changed files with 36 additions and 41 deletions
77
sectorlisp.S
77
sectorlisp.S
|
|
@ -55,7 +55,7 @@ kCdr: .asciz "CDR" # ordering matters
|
||||||
kCons: .asciz "CONS" # ordering matters
|
kCons: .asciz "CONS" # ordering matters
|
||||||
kEq: .asciz "EQ" # needs to be last
|
kEq: .asciz "EQ" # needs to be last
|
||||||
|
|
||||||
begin: xor %ax,%ax
|
begin: xor TWO,TWO
|
||||||
push %cs # memory model ds=es=ss=cs
|
push %cs # memory model ds=es=ss=cs
|
||||||
pop %ds
|
pop %ds
|
||||||
push %cs
|
push %cs
|
||||||
|
|
@ -63,17 +63,17 @@ begin: xor %ax,%ax
|
||||||
push %cs
|
push %cs
|
||||||
cli # disable interrupts
|
cli # disable interrupts
|
||||||
pop %ss # disable nonmaskable interrupts
|
pop %ss # disable nonmaskable interrupts
|
||||||
mov %ax,%sp # use null pointer as our stack
|
mov TWO,%sp # use null pointer as our stack
|
||||||
sti # enable interrupts
|
sti # enable interrupts
|
||||||
cld # direction forward
|
cld # direction forward
|
||||||
mov $2,TWO
|
inc TWO
|
||||||
main: mov $'\n',%dl
|
inc TWO
|
||||||
mov $0x8000,g_mem
|
main: mov $0x8000,g_mem # dl (g_look) is zero or cr
|
||||||
call GetToken
|
call GetToken
|
||||||
call GetObject
|
call GetObject
|
||||||
xor %dx,%dx
|
xor %dx,%dx
|
||||||
call Eval
|
call Eval
|
||||||
xchg %ax,%di
|
xchg %ax,%si
|
||||||
call PrintObject
|
call PrintObject
|
||||||
mov $'\r',%al
|
mov $'\r',%al
|
||||||
call PutChar
|
call PutChar
|
||||||
|
|
@ -81,52 +81,48 @@ main: mov $'\n',%dl
|
||||||
|
|
||||||
GetToken: # GetToken():al, dl is g_look
|
GetToken: # GetToken():al, dl is g_look
|
||||||
mov g_token,%di
|
mov g_token,%di
|
||||||
mov %di,%si
|
|
||||||
1: mov %dl,%al
|
1: mov %dl,%al
|
||||||
cmp $' ',%al
|
cmp $' ',%al
|
||||||
jbe 2f
|
jbe 2f
|
||||||
stosb
|
stosb
|
||||||
xchg %ax,%si
|
xchg %ax,%si
|
||||||
2: call GetChar
|
2: call GetChar # exchanges dx and ax
|
||||||
xchg %ax,%dx # dl = g_look
|
|
||||||
cmp $' ',%al
|
cmp $' ',%al
|
||||||
jbe 1b
|
jbe 1b
|
||||||
cmp $')',%al
|
cmp $')',%al
|
||||||
jbe 3f
|
jbe 3f
|
||||||
cmp $')',%dl
|
cmp $')',%dl # dl = g_look
|
||||||
ja 1b
|
ja 1b
|
||||||
3: movb ZERO,(%di)
|
3: movb ZERO,(%di)
|
||||||
xchg %si,%ax
|
xchg %si,%ax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.PutObject: # .PutObject(c:al,x:di)
|
.PutObject: # .PutObject(c:al,x:si)
|
||||||
call PutChar # preserves di
|
call PutChar # preserves si
|
||||||
PrintObject: # PrintObject(x:di)
|
PrintObject: # PrintObject(x:si)
|
||||||
test %di,%di # set sf=1 if cons
|
test %si,%si # set sf=1 if cons
|
||||||
js .PrintList # jump if cons
|
jns .PrintAtom # jump if cons
|
||||||
.PrintAtom:
|
|
||||||
mov %di,%si # lea g_str(%di),%si
|
|
||||||
.PrintString: # nul-terminated in si
|
|
||||||
lodsb
|
|
||||||
test %al,%al # test for nul terminator
|
|
||||||
jz .ret # -> ret
|
|
||||||
call PutChar
|
|
||||||
jmp .PrintString
|
|
||||||
.PrintList:
|
.PrintList:
|
||||||
mov $'(',%al
|
mov $'(',%al
|
||||||
2: push (TWO,%di) # save 1 Cdr(x)
|
2: push (TWO,%si)
|
||||||
mov (%di),%di # di = Car(x)
|
mov (%si),%si
|
||||||
call .PutObject
|
call .PutObject
|
||||||
pop %ax # restore 1
|
|
||||||
test %ax,%ax
|
|
||||||
jz 4f # jump if nil
|
|
||||||
xchg %ax,%di
|
|
||||||
mov $' ',%al
|
mov $' ',%al
|
||||||
|
pop %si # restore 1
|
||||||
|
test %si,%si
|
||||||
js 2b # jump if cons
|
js 2b # jump if cons
|
||||||
|
jz 4f # jump if nil
|
||||||
mov $249,%al # bullet (A∙B)
|
mov $249,%al # bullet (A∙B)
|
||||||
call .PutObject
|
call .PutObject
|
||||||
4: mov $')',%al
|
4: mov $')',%al
|
||||||
jmp PutChar
|
jmp PutChar
|
||||||
|
.PrintString: # nul-terminated in si
|
||||||
|
call PutChar
|
||||||
|
.PrintAtom:
|
||||||
|
lodsb
|
||||||
|
test %al,%al # test for nul terminator
|
||||||
|
jnz .PrintString # -> ret
|
||||||
|
ret
|
||||||
|
|
||||||
GetObject: # called just after GetToken
|
GetObject: # called just after GetToken
|
||||||
cmpb $'(',%al
|
cmpb $'(',%al
|
||||||
|
|
@ -155,16 +151,15 @@ GetObject: # called just after GetToken
|
||||||
5: pop %ax # restore 1
|
5: pop %ax # restore 1
|
||||||
.ret: ret
|
.ret: ret
|
||||||
|
|
||||||
GetChar:
|
GetChar: # GetChar→al:dl
|
||||||
xor %ax,%ax # get keystroke
|
xor %ax,%ax # get keystroke
|
||||||
int $0x16 # keyboard service
|
int $0x16 # keyboard service
|
||||||
# ah is bios scancode
|
# ah is bios scancode
|
||||||
# al is ascii character
|
# al is ascii character
|
||||||
PutChar:
|
PutChar:mov $0x0e,%ah # teletype output al cp437
|
||||||
mov $0x0e,%ah # teletype output al cp437
|
|
||||||
int $0x10 # vidya service
|
int $0x10 # vidya service
|
||||||
cmp $'\r',%al # don't clobber
|
cmp $'\r',%al # don't clobber
|
||||||
jne .ret
|
jne 1f # xchg dx,ax and ret
|
||||||
mov $'\n',%al
|
mov $'\n',%al
|
||||||
jmp PutChar
|
jmp PutChar
|
||||||
|
|
||||||
|
|
@ -193,6 +188,7 @@ Evlis: test %di,%di # Evlis(m:di,a:dx):ax
|
||||||
pop %di # restore 1
|
pop %di # restore 1
|
||||||
push %ax # save 2
|
push %ax # save 2
|
||||||
call Evlis
|
call Evlis
|
||||||
|
# jmp xCons
|
||||||
|
|
||||||
xCons: pop %di # restore 2
|
xCons: pop %di # restore 2
|
||||||
Cons: xchg %ax,%si # Cons(m:di,a:ax):ax
|
Cons: xchg %ax,%si # Cons(m:di,a:ax):ax
|
||||||
|
|
@ -283,15 +279,14 @@ Cdr: scasw # increments our data index by 2
|
||||||
Car: mov (%di),%ax # contents of address register!!
|
Car: mov (%di),%ax # contents of address register!!
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.Assoc: mov (TWO,%si),%dx # dx = Cdr(y)
|
Assoc: mov %dx,%di # Assoc(x:ax,y:dx):ax
|
||||||
Assoc: mov %dx,%si # Assoc(x:ax,y:dx):ax
|
|
||||||
test %dx,%dx # nil test
|
test %dx,%dx # nil test
|
||||||
jz .retF
|
jz .retF # return nil if end of list
|
||||||
mov (%si),%di # bx = Car(y)
|
mov (TWO,%di),%dx # we assume Eval() saved dx
|
||||||
cmp %ax,(%di) # (%di) = Caar(y)
|
mov (%di),%di
|
||||||
jne .Assoc
|
scasw
|
||||||
mov (TWO,%di),%ax # ax = Cdar(y)
|
jne Assoc
|
||||||
ret
|
jmp Car
|
||||||
|
|
||||||
1: mov (TWO,%di),%di # di = Cdr(c)
|
1: mov (TWO,%di),%di # di = Cdr(c)
|
||||||
Evcon: push %di # save c
|
Evcon: push %di # save c
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue