用汇编语言编写程序,建立一数据表,表中存放1-9的平方,查表求某数字的平方。
发布网友
发布时间:2022-04-23 09:35
我来回答
共1个回答
热心网友
时间:2023-10-09 16:09
程序如下:
;--------------------------------------------------------------------
DATA SEGMENT
; 数据表格.
TABLE DW 0, 1, 4, 9, 16, 25, 36, 49, 64, 81
DATA ENDS
;--------------------------
STACK SEGMENT
DW 128 DUP(0)
STACK ENDS
;--------------------------
CODE SEGMENT
ASSUME CS: CODE, DS: DATA, SS: STACK
START:
MOV AX, DATA
MOV DS, AX
MOV ES, AX
M_LOOP:
MOV AH, 1
INT 21H
CMP AL, 1BH
JZ EXIT
CMP AL, 30H
JL M_LOOP
CMP AL, 39H
JG M_LOOP
SUB AL, 30H
;------------------------------
MOV BX, TABLE
PUSH CX
SHL AL, 1
MOV AH, AL
INC AH
XLAT
MOV CL, AL
MOV AL, AH
XLAT
MOV CH, AL
MOV AX, CX
POP CX
;------------------------------
CALL CR_LF
CALL OUT_AX
CALL CR_LF
JMP M_LOOP
;------------------------------
EXIT:
MOV AX, 4C00H ;EXIT TO OPERATING SYSTEM.
INT 21H
;--------------------------------------------
OUT_AX PROC NEAR
PUSH BX
MOV DL, 0
CALL OUT_ASC
MOV BL, 100
DIV BL
MOV DL, AL
CALL OUT_ASC
MOV AL, AH
XOR AH, AH
MOV BL, 10
DIV BL
MOV DL, AL
CALL OUT_ASC
MOV DL, AH
CALL OUT_ASC
POP BX
RET
OUT_AX ENDP
;--------------------------------------------
OUT_ASC PROC NEAR
ADD DL, 30H
CALL OUT_DL
RET
OUT_ASC ENDP
;--------------------------------------------
CR_LF PROC NEAR
MOV DL, 10
CALL OUT_DL
MOV DL, 13
CALL OUT_DL
RET
CR_LF ENDP
;--------------------------------------------
OUT_DL PROC NEAR
PUSH AX
MOV AH, 02H
INT 21H
POP AX
RET
OUT_DL ENDP
;--------------------------------------------
CODE ENDS
END START
------------------------------------------------------------------