You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<name>
Name of macro
<argc>
Number of arguments
<macrobody>
Definition of macro
Example:
; a NASM macro to add two numbers and store it in rax
%macro sumTwoNumbers 2
mov rax, %1 ; move argument 1 into rax
add rax, %2 ; add rax and argument 2 and store it in rax
%endmacro
File Permissions:
We need to get the permission value (octal) first
r = read, w = write, x = execute, sst = special attributes
Write to File:
Example:
section .data
filename db "myfile.txt", 0 ; null-terminated file string
text db "Here's some text." ; text to write to file
textLen equ $ - text ; length of text to write
section .text
global _start
_start:
mov rax, 2 ; argument to call 'sys_open'
mov rdi, filename ; argument for file name
mov rsi, 64+1 ; argument for create (64) and write (1) flag
mov rdx, 0644o ; argument for file permission value, suffix 'o' for octal
syscall
mov rdi, rax ; argument for file descriptor (stored in rax)
mov rax, 1 ; argument to call 'sys_write'
mov rsi, text ; argument for text to write to file
mov rdx, textLen ; argument for text length (textLen)
syscall
mov rax, 3 ; argument to call 'sys_close'
syscall
mov rax, 60 ; argument to call 'sys_exit'
mov rdi, 0 ; argument for error code (0)
syscall
Size Operands:
Size (bits)
Operands
8
byte, DB, RESB
16
word, DW, RESW
32
dword, DD, RESD
64
qword, DQ, RESQ
80
tword, DT, REST
128
oword, DO, DDQ, RESO, RESDQ
256
yword, DY, RESY
512
zword, DZ, RESZ
Miscellanous:
Use %include 'file.h' to include other NASM files
When using mul or div, the result is stored int rdx:rax, where rdx is the high bits, and rax is the low bits