程序设计:
顺序程序设计
例,将一个非压缩BCD码转为两个ACSII码
DATA SEGMENT ; 定义数据段
BCD_BUF DB 96H
ACI_BUF DB 2DUP(?)
DATA ENDS
; 定义代码段
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:MOV AX, DATA
MOV DS, AX
MOV AL, BCD_BUF
MOV BL, BCD_BUF
MOV CL, 4
SHR AL, CL
ADD AL, 30H
MOV ACI_BUF, AL
AND BL, 0FH
ADD BL, 30H
MOV ACI_BUF + 1, BL
CODE ENDS
END START
例2,TABLE中存放10个字节数据。用读表方式取得第x个放入RESULT里
DATA SEGMENT
TABLE DB 00H, 01H, 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H
POS DB X
RESULT DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV BX, OFFSET TABLE
MOV AL, POS
XLAT
MOV RESULT, AL
CODE ENDS
END START
分支程序设计
例,将 X, Y, Z三个无符号数中较大的数放入MAX
; 数据段
DATA SEGMENT
X DB 20H
Y DB 30H
Z DB 25H
MAX DB ?
DATA ENDS
; 代码段
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, X
CMP AL, Y
JNB DOZ
MOV AL, Y
DOZ:
CMP AL, Z
JNB OK
MOV AL, Z
OK:
MOV MAX, AL
CODE ENDS
END START