EQU指令
EQU指令用于定义常量。EQU指令的语法如下-
CONSTANT_NAME EQU expression
例如,
然后,您可以在代码中使用此常量值,例如-
mov ecx, TOTAL_STUDENTS
cmp eax, TOTAL_STUDENTS
EQU语句的操作数可以是表达式-
LENGTH equ 20
WIDTH equ 10
AREA equ length * width
以上代码段将AREA定义为200。
以下示例说明了EQU指令的使用-
SYS_EXIT equ 1
SYS_WRITE equ 4
STDIN equ 0
STDOUT equ 1
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg1
mov edx, len1
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg2
mov edx, len2
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg3
mov edx, len3
int 0x80
mov eax,SYS_EXIT ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg1 db 'Hello, programmers!',0xA,0xD
len1 equ $ - msg1
msg2 db 'Welcome to the world of,', 0xA,0xD
len2 equ $ - msg2
msg3 db 'Linux assembly programming! '
len3 equ $- msg3
尝试一下
编译并执行上述代码后,将产生以下结果-
Hello, programmers!
Welcome to the world of,
Linux assembly programming!