corrections in 03 compiler, better hello world program!
This commit is contained in:
parent
eb2aadf9bf
commit
8bbacdc331
4 changed files with 176 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
all: out02
|
all: out02 out03
|
||||||
out02: in02 ../02/out01
|
out02: in02 ../02/out01
|
||||||
../02/out01
|
../02/out01
|
||||||
out03: out02 in03
|
out03: out02 in03
|
||||||
|
|
1
03/ex03
1
03/ex03
|
@ -39,3 +39,4 @@ div
|
||||||
call A
|
call A
|
||||||
str Here is some text which will be put in the executable!
|
str Here is some text which will be put in the executable!
|
||||||
?CaD:label
|
?CaD:label
|
||||||
|
|
||||||
|
|
145
03/in02
145
03/in02
|
@ -770,6 +770,107 @@ im
|
||||||
##38. ascii '8'
|
##38. ascii '8'
|
||||||
je
|
je
|
||||||
:-=8 read 8 bytes
|
:-=8 read 8 bytes
|
||||||
|
im
|
||||||
|
##78. ascii 'x'
|
||||||
|
je
|
||||||
|
:-=#
|
||||||
|
im
|
||||||
|
##64. ascii 'd'
|
||||||
|
je
|
||||||
|
:-=#
|
||||||
|
im
|
||||||
|
##27. ascii '
|
||||||
|
je
|
||||||
|
:-=#
|
||||||
|
// register transfer. start by writing 48 89
|
||||||
|
im
|
||||||
|
--tx
|
||||||
|
IA
|
||||||
|
im
|
||||||
|
##2.
|
||||||
|
DA
|
||||||
|
im
|
||||||
|
--wr
|
||||||
|
cl
|
||||||
|
// get index of first register
|
||||||
|
im
|
||||||
|
--LI
|
||||||
|
BA
|
||||||
|
zA
|
||||||
|
lb
|
||||||
|
BA
|
||||||
|
im
|
||||||
|
--r#
|
||||||
|
cl
|
||||||
|
DA
|
||||||
|
// get index of first register
|
||||||
|
im
|
||||||
|
##2.
|
||||||
|
BA
|
||||||
|
im
|
||||||
|
--LI
|
||||||
|
+B
|
||||||
|
BA
|
||||||
|
zA
|
||||||
|
lb
|
||||||
|
BA
|
||||||
|
im
|
||||||
|
--r#
|
||||||
|
cl
|
||||||
|
<I
|
||||||
|
03 shift left by 3
|
||||||
|
BA
|
||||||
|
im
|
||||||
|
##c0.
|
||||||
|
|B or with 0xc0
|
||||||
|
BD
|
||||||
|
|B or with dest
|
||||||
|
BA
|
||||||
|
im
|
||||||
|
--wb write that byte
|
||||||
|
cl
|
||||||
|
jm
|
||||||
|
:-rl next line
|
||||||
|
::tx
|
||||||
|
48
|
||||||
|
89
|
||||||
|
// get register index of rbx
|
||||||
|
::r#
|
||||||
|
im
|
||||||
|
##41. 'A'
|
||||||
|
je
|
||||||
|
:-r0
|
||||||
|
im
|
||||||
|
##42. 'B'
|
||||||
|
je
|
||||||
|
:-r3
|
||||||
|
im
|
||||||
|
##43. 'C'
|
||||||
|
je
|
||||||
|
:-r1
|
||||||
|
im
|
||||||
|
##44. 'D'
|
||||||
|
je
|
||||||
|
:-r2
|
||||||
|
im
|
||||||
|
##49. 'I'
|
||||||
|
je
|
||||||
|
:-r6
|
||||||
|
im
|
||||||
|
##4a. 'J'
|
||||||
|
je
|
||||||
|
:-r7
|
||||||
|
im
|
||||||
|
##52. 'R'
|
||||||
|
je
|
||||||
|
:-r5
|
||||||
|
im
|
||||||
|
##53. 'S'
|
||||||
|
je
|
||||||
|
:-r4
|
||||||
|
jm
|
||||||
|
:-!r
|
||||||
|
::=#
|
||||||
// it's a number.
|
// it's a number.
|
||||||
im
|
im
|
||||||
##2.
|
##2.
|
||||||
|
@ -1105,6 +1206,10 @@ im
|
||||||
##53. 'S'
|
##53. 'S'
|
||||||
je
|
je
|
||||||
:-AS
|
:-AS
|
||||||
|
im
|
||||||
|
##30. '0'
|
||||||
|
je
|
||||||
|
:-A0
|
||||||
// it's a number
|
// it's a number
|
||||||
im
|
im
|
||||||
##3.
|
##3.
|
||||||
|
@ -1404,6 +1509,10 @@ DA
|
||||||
im
|
im
|
||||||
##8. syscall 8 = lseek
|
##8. syscall 8 = lseek
|
||||||
sy
|
sy
|
||||||
|
BA
|
||||||
|
im
|
||||||
|
##400004.
|
||||||
|
+B add address of start of file + 4 bytes to write relative offset
|
||||||
nA negate current address
|
nA negate current address
|
||||||
BR
|
BR
|
||||||
+B get relative address
|
+B get relative address
|
||||||
|
@ -2125,6 +2234,36 @@ re
|
||||||
im
|
im
|
||||||
##1.
|
##1.
|
||||||
re
|
re
|
||||||
|
// return 2
|
||||||
|
::r2
|
||||||
|
im
|
||||||
|
##2.
|
||||||
|
re
|
||||||
|
// return 3
|
||||||
|
::r3
|
||||||
|
im
|
||||||
|
##3.
|
||||||
|
re
|
||||||
|
// return 4
|
||||||
|
::r4
|
||||||
|
im
|
||||||
|
##4.
|
||||||
|
re
|
||||||
|
// return 5
|
||||||
|
::r5
|
||||||
|
im
|
||||||
|
##5.
|
||||||
|
re
|
||||||
|
// return 6
|
||||||
|
::r6
|
||||||
|
im
|
||||||
|
##6.
|
||||||
|
re
|
||||||
|
// return 7
|
||||||
|
::r7
|
||||||
|
im
|
||||||
|
##7.
|
||||||
|
re
|
||||||
// exit with code in rax
|
// exit with code in rax
|
||||||
::ex
|
::ex
|
||||||
JA
|
JA
|
||||||
|
@ -2557,6 +2696,12 @@ DA
|
||||||
im
|
im
|
||||||
##8. lseek
|
##8. lseek
|
||||||
sy
|
sy
|
||||||
|
// set line number to 0
|
||||||
|
im
|
||||||
|
--L#
|
||||||
|
BA
|
||||||
|
zA
|
||||||
|
sq
|
||||||
// now go back to do the second pass
|
// now go back to do the second pass
|
||||||
jm
|
jm
|
||||||
:-2p
|
:-2p
|
||||||
|
|
37
03/in03
37
03/in03
|
@ -1,14 +1,35 @@
|
||||||
; write to stdout
|
; write to stdout
|
||||||
J=d1
|
B=:hello_world
|
||||||
I=:hello_world
|
call :puts
|
||||||
D=:hello_world_end
|
J=d0
|
||||||
; calculate length by subtracting end from start
|
|
||||||
D-=I
|
|
||||||
syscall d1
|
|
||||||
J=d42
|
|
||||||
syscall x3c
|
syscall x3c
|
||||||
|
|
||||||
:hello_world
|
:hello_world
|
||||||
str Hello, world!
|
str Hello, world!
|
||||||
xa
|
xa
|
||||||
:hello_world_end
|
x0
|
||||||
|
|
||||||
|
; output null-terminated string in rbx
|
||||||
|
:puts
|
||||||
|
call :strlen
|
||||||
|
I=D
|
||||||
|
D=A
|
||||||
|
J=d1
|
||||||
|
syscall d1
|
||||||
|
return
|
||||||
|
|
||||||
|
; calculate length of string in rbx
|
||||||
|
; keeps pointer to start of string in rdx, end of string in rsi
|
||||||
|
:strlen
|
||||||
|
; keep pointer to start of string
|
||||||
|
D=B
|
||||||
|
I=B
|
||||||
|
:strlen_loop
|
||||||
|
C=1I
|
||||||
|
?C=0:strlen_loop_end
|
||||||
|
I+=d1
|
||||||
|
!:strlen_loop
|
||||||
|
:strlen_loop_end
|
||||||
|
I-=D
|
||||||
|
A=I
|
||||||
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue