Second assembly operation

xiaoxiao2021-03-06  116

Enter a string integer (Length <= 9) by the keyboard, convert the string into an integer, and press 16 and 10.

The length of the integer is 9, which exceeds 16 bits, and the operation of the simple use of 8086 can no longer meet, the carry of addition will be lost, and the multi-Division is likely to appear overflow. So use 32-bit registers so that 386 instructions are used. If you don't have to use 386 instructions, you can use two registers to operate with 16 bits and low 16 bits. Below is the source code of 386 instruction Enter Macro Mov DL, 0AH MOV AH, 2H INT 21H MOV DL, 0DH MOV AH, 2H INT 21h Endm.Model HEX.386 .DATA MSG DB 'INPUT NUMBERS (Length <= 9): $ '.Stack DB 100 DUP (?). Code main proc Far; *************************************** Start : Push DS MOV AX, 0 Push Ax Mov AX, @ Data MoV DS, AX Mov DX, Offset MSG MOV AH, 9 INT 21H Call Rec Enter Call tohex Enter Call Dec1 Enter Ret Main Endp; -------- -------------------------- Rec proc Near; subroutine REC is used to receive an integer MOV EBX, 0; Put it in EBX NewNum: MOV AH, 01 INT 21h SUB AL, 30H JL EXIT CMP AL, 9D JG EXIT CBW XCHG EX, EBX MOV ECX, 10D MUL ECX XCHG EAX, EBX ADD EBX, EAX JMP NewNumexit: RetRec ENDP ; ------------------------------------ tohex proc Near; subroutine tohex is the number in EBX Output MOV CH, 8ROTATE: MOV CL, 4 ROL E with 16 BX, Cl Mov Al, BL and Al, 0FH Add Al, 30H CMP AL, 3AH JL Print Add Al, 7HPRINT: MOV DL, Al Mov Ah, 2H INT 21h Dec Ch Jnz Rotate Rettohex Endp; ------- -------------------------- Dec1 proc NEAR;

转载请注明原文地址:https://www.9cbs.com/read-99963.html

New Post(0)