x86 彙編/MASM 語法
外觀
< X86 彙編
本頁將解釋使用 MASM 語法的 x86 程式設計,並將討論如何使用 MASM 的宏功能。其他彙編器,如 NASM 和 FASM,使用與 MASM 不同的語法,但它們都使用 Intel 語法。
MASM 指令的運算子通常與 GAS 指令相反。例如,指令通常寫成 指令 目標, 源。
mov 指令,寫成如下
mov al, 05h
將把值 5 移動到 al 暫存器。
MASM 不使用指令字尾來區分大小(位元組、字、雙字等)。
MASM 被稱為“宏彙編器”或“Microsoft 彙編器”,這取決於你問誰。但無論你的答案來自哪裡,事實是 MASM 有一個強大的宏引擎,以及許多立即可用的內建宏。
MASM 有大量指令可以控制某些設定和行為。與 NASM 或 FASM 相比,它有更多指令。
.model small
.stack 100h
.data
msg db 'Hello world!$'
.code
start:
mov ah, 09h ; Display the message
lea dx, msg
int 21h
mov ax, 4C00h ; Terminate the executable
int 21h
end start
;template for masm510 programming using simplified segment definition
title YOUR TITLE HERE
page 60,132
;tell the assembler to create a nice .lst file for the convenience of error pruning
.model small
;maximum of 64KB for data and code respectively
.stack 64
.data
;PUT YOUR DATA DEFINITION HERE
.code
main proc far
;This is the entry point,you can name your procedures by altering "main" according to some rules
mov ax,@DATA
;load the data segment address,"@" is the opcode for fetching the offset of "DATA","DATA" could be change according to your previous definition for data
mov ds,ax
;assign value to ds,"mov" cannot be used for copying data directly to segment registers(cs,ds,ss,es)
;PUT YOUR CODE HERE
mov ah,4ch
int 21h
;terminate program by a normal way
main endp
;end the "main" procedure
end main
;end the entire program centering around the "main" procedure