.The model flat, stdcall
Option casemap: none
The include \ masm32 \ include \ Windows inc
The include \ masm32 \ include \ kernel32 inc
The include \ masm32 \ include \ masm32 inc
Includelib \ masm32 \ lib \ kernel32 lib
Includelib \ masm32 \ lib \ masm32 lib
.data
Var1 BYTE "both Please input a decimal number (0 ~ 4294967295) :", 0
Var2 BYTE "The hexdecimal number is:", 0 dh, ah, 0 0
Var3 DWORD 0 h
Var4 DWORD 0 h
20 DUP cin BYTE (0)
The code
Start:
The main PROC
Invoke StdOut, addr var1
Invoke StdIn, addr cin, 20
Invoke StdOut, addr var2
CALL dec2dw
CALL DW2E
Invoke StdOut, addr var4
Invoke ExitProcess, 0
The main ENDP
Dec2dw PROC
MOV ECX, LENGTHOF cin
MOV EDI, OFFSET cin
MOV DX, 0
MOV AX, 0
L1:; And enter a decimal value
The ADD AX, (EDI)
SUB AX, 30 h
MOV DX, ah 0
The MUL DX
The ADD EDI, TYPE cin
LOOP L1
MOV EDI, 0
MOV ECX, 100 h
L2:; Pour remainder exist VAR3
MOV BL, 10 h
DIV BL
; The remainder in the AH
MOV BYTE PTR (EDI), AH
INC EDI
CMP AL, 0
JE L3
LOOP L2
MOV ECX, EDI
MOV EAX, 0
L3:
DEC EDI
MOV EDX, var3 (EDI)
MOV var4 [EAX], EDX
INC EAX
LOOP L3
Ret
Dec2dw ENDP
DW2E PROC
MOV EAX, 0 h
MOV ECX, SIZEOF var4
L4:
CMP var4 (EAX), 9
JA ABCD
The ADD var4 (EAX), 30 h
INC EAX
LOOP L4
JMP R4
The ABCD:
The ADD var4 (EAX), 37 h
INC EAX
JMP L4
R4: ret
DW2E ENDP
The end start
CodePudding user response:
Running wrong, debugging programs on ah, you this coarse, dec2dw procedure used for ecx is wrong in the beginning, it should be input numerical character number, how can the size of the input buffer of the come, should cannot lose full; Calculation of the following also has a problem, one character at a time, with the ax is wrong; .CodePudding user response:
Just learn what won't ah, mainly, this should be how to changeCodePudding user response:
Just learning, how to change, since be masm32, machines are masm32 program, its directory M32LIB directory, there is a similar code, such as dw2ah. Asm is converted to hexadecimal string will value, a2dw. Asm is similar to the input of the string is converted to the corresponding numerical procedure, you can refer to,