Files
Operating-System/Experiment/asm-exp/实验三/code/EX3_3_AbsoluteDifference.asm
2026-06-25 00:09:09 +08:00

34 lines
577 B
NASM
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
; 实验三-3分支程序示例2 - 求两个数的差的绝对值
; 功能求X和Y的差的绝对值存入Z
DATA SEGMENT
X DB 5
Y DB 3
Z DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, X
CMP AL, Y
JZ EQUAL ;如果X=Y则跳转到EQUAL
JNS PLUS ;如果X>Y则跳转到PLUS正数
MOV BL, Y
SUB BL, AL
MOV Z, BL
JMP EXIT
PLUS:
MOV BL, AL
SUB BL, Y
MOV Z, BL
JMP EXIT
EQUAL:
MOV Z, 0
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START