2021-11-14 00:33:40 -05:00
|
|
|
; You can use registers like variables: rax = A, rbx = B, rcx = C, rdx = D, rsi = I, rdi = J, rsp = S, rbp = R
|
|
|
|
; However, because of the way things are implemented, you should be careful about using A/B as variables:
|
|
|
|
; they sometimes might not work correctly, and will be overwritten by a lot of statements
|
|
|
|
|
|
|
|
; set register to...
|
|
|
|
; decimal
|
|
|
|
D=d123
|
|
|
|
; hexadecimal
|
|
|
|
D=x1ef
|
|
|
|
; another register
|
|
|
|
D=R we can have a comment here and in some other places. not after numbers or labels though.
|
|
|
|
; label address
|
|
|
|
D=:label
|
|
|
|
; add
|
2021-11-13 15:02:23 -05:00
|
|
|
D+=d4
|
2021-11-14 00:33:40 -05:00
|
|
|
D+=R
|
|
|
|
; subtract
|
|
|
|
D-=d123
|
|
|
|
D-=R
|
|
|
|
; left/right shift (only rcx is supported for variable shifts)
|
|
|
|
D<=C
|
|
|
|
D<=d33
|
|
|
|
D>=C
|
|
|
|
D>=x12
|
|
|
|
; arithmetic right shift
|
2021-11-13 13:48:27 -05:00
|
|
|
D]=d7
|
|
|
|
D]=C
|
2021-11-14 00:33:40 -05:00
|
|
|
; bitwise xor, or, and
|
|
|
|
D^=R
|
|
|
|
D|=R
|
|
|
|
D&=R
|
|
|
|
D^=d1
|
|
|
|
D|=d1
|
|
|
|
D&=d1
|
|
|
|
; bitwise not
|
|
|
|
; (this sets D to ~D)
|
|
|
|
~D
|
|
|
|
; dereference
|
|
|
|
; set 8 bytes at rdx to rbp
|
|
|
|
8D=R
|
|
|
|
; set 4 bytes at rdx to ebp
|
|
|
|
4D=R
|
|
|
|
2D=R
|
|
|
|
1D=R
|
|
|
|
; set rcx/ecx/cx/cl to 8/4/2/1 bytes at rdx
|
|
|
|
C=8D
|
|
|
|
C=4D
|
|
|
|
C=2D
|
|
|
|
C=1D
|
|
|
|
; call a function
|
|
|
|
call :function
|
|
|
|
; return
|
|
|
|
return
|
|
|
|
; label declarations
|
|
|
|
;:function
|
|
|
|
;:label
|
|
|
|
; literal byte
|
2021-11-13 13:48:27 -05:00
|
|
|
x4b
|
2021-11-14 00:33:40 -05:00
|
|
|
'H
|
|
|
|
'i
|
|
|
|
; string
|
|
|
|
str This text will appear in the executable!
|
|
|
|
; unconditional jump
|
2021-11-13 13:48:27 -05:00
|
|
|
!:label
|
2021-11-14 00:33:40 -05:00
|
|
|
; conditional jump
|
|
|
|
?R<S:label
|
|
|
|
?R=S:label
|
|
|
|
?R!S:label
|
|
|
|
?R>S:label
|
|
|
|
; (unsigned comparisons above/below)
|
|
|
|
?RaS:label
|
|
|
|
?RbS:label
|
|
|
|
; syscall
|
2021-11-13 13:48:27 -05:00
|
|
|
syscall x3c
|
2021-11-14 00:33:40 -05:00
|
|
|
; align to 8 bytes
|
2021-11-13 14:13:16 -05:00
|
|
|
align
|
2021-11-14 00:33:40 -05:00
|
|
|
; reserve some number of bytes of memory
|
2021-11-13 14:13:16 -05:00
|
|
|
reserve d1000
|
2021-11-14 00:33:40 -05:00
|
|
|
; signed/unsigned multiply/divide
|
2021-11-13 14:32:00 -05:00
|
|
|
imul
|
|
|
|
idiv
|
|
|
|
mul
|
|
|
|
div
|
2021-11-14 00:33:40 -05:00
|
|
|
; e.g. to compute 5*3 into rcx (note rdx is wiped in the process):
|
|
|
|
A=d5
|
|
|
|
B=d3
|
|
|
|
mul
|