2323// Compatible with the original hardware
2424
2525 .code16
26+ .set save,-10
27+ .set look,start+2
2628 .globl _start
2729_start: .asciz "NIL" # dec %si ; dec %cx ; dec %sp
2830kT: .asciz "T" # add %dl,(%si) boot A:\ DL=0
@@ -36,37 +38,53 @@ kCdr: .asciz "CDR" # ordering matters
3638kCons: .asciz "CONS" # ordering matters
3739kEq: .asciz "EQ" # needs to be last
3840
39- begin: push %cs # that means ss = ds = es = cs
41+ begin: mov $2 ,%bx
42+ mov $0x8000 ,%cx
43+ main: cli
44+ push %cs # that means ss = ds = es = cs
4045 pop %ds # noting ljmp set cs to 0x7c00
4146 push %cs # that's the bios load address
4247 pop %es # therefore NULL points to NUL
4348 push %cs # terminated NIL string above!
4449 pop %ss # errata exists but don't care
4550 xor %sp ,%sp # use highest address as stack
46- mov $2 ,%bx
47- main: mov $0x8000 ,%cx # dl (g_look) is zero or cr
51+ sti
4852 call GetToken
4953 call GetObject
54+ mov %dx ,save
5055 call Eval
51- xchg %ax ,%si
56+ test %ax ,%ax
57+ jns Print
58+ push %ax
59+ xchg %ax ,%di
60+ xchg %dx ,%ax
61+ call Cons
62+ xchg %ax ,%dx
63+ pop %ax
64+ Print: xchg %ax ,%si
5265 call PrintObject
5366 mov $'\r',%al
5467 call PutChar
5568 jmp main
5669
57- GetToken: # GetToken():al, dl is g_look
70+ GetToken: # GetToken():al
5871 mov %cx ,%di
59- 1: mov %dl ,%al
72+ 1: mov look ,%al
6073 cmp $' ', %al
6174 jbe 2f
6275 stosb
6376 xchg %ax ,%si
64772: call GetChar # exchanges dx and ax
78+ cmp $'\b',%al
79+ jne 4f
80+ dec %di
81+ jmp 2b
82+ 4: xchg %ax ,look
6583 cmp $' ', %al
6684 jbe 1b
6785 cmp $')', %al
6886 jbe 3f
69- cmp $')', %dl # dl = g_look
87+ cmpb $')', look
7088 ja 1b
71893: mov %bh ,(%di ) # bh is zero
7290 xchg %si ,%ax
@@ -123,14 +141,21 @@ Intern: push %cx # Intern(cx,di): ax
123141 jmp 1b
1241422: rep movsb # memcpy(di,si,cx)
1251439: pop %cx
126- ret
144+ 3: ret
145+
146+ Undef: push %ax
147+ mov $'?', %al
148+ call PutChar
149+ pop %ax
150+ mov save,%dx
151+ jmp Print
127152
128153GetChar: xor %ax ,%ax # GetChar→al:dl
129154 int $0x16 # get keystroke
130155PutChar: mov $0x0e ,%ah # prints CP-437
131156 int $0x10 # vidya service
132157 cmp $'\r',%al # don't clobber
133- jne 1f # look xchg ret
158+ jne 3b # look xchg ret
134159 mov $'\n',%al
135160 jmp PutChar
136161
@@ -183,6 +208,15 @@ Gc: cmp %dx,%di # Gc(x:di,A:dx,B:si):ax
183208 add %dx ,%ax
184209 ret
185210
211+ Assoc: mov %dx ,%si # Assoc(x:ax,y:dx):ax
212+ 1: test %si ,%si
213+ jns Undef
214+ mov (%si ),%di
215+ mov (%bx ,%si ),%si
216+ scasw
217+ jne 1b
218+ jmp Car
219+
186220GetList: call GetToken
187221 cmp $')', %al
188222 je .retF
@@ -234,13 +268,6 @@ Cdr: scasw # increments our data index by 2
234268Car: mov (%di ),%ax # contents of address register!!
2352692: ret
236270
237- Assoc: mov %dx ,%si # Assoc(x:ax,y:dx):ax
238- 1: mov (%si ),%di
239- mov (%bx ,%si ),%si
240- scasw
241- jne 1b
242- jmp Car
243-
2442711: mov (%bx ,%di ),%di # di = Cdr(c)
245272Evcon: push %di # save c
246273 mov (%di ),%si # di = Car(c)
0 commit comments