Home > other >  Assembly will be result in hexadecimal number converted to ASCII display output, I why not correct,
Assembly will be result in hexadecimal number converted to ASCII display output, I why not correct,

Time:12-04

Titled: calculate S=1 + 2 * 3 + 4 + 3 * 4 * 5 +... + N * (N + 1), the sum until N * (N + 1) & gt; 200
Results of 038 dh, but after I convert the ASCII code of the output is not the result,
The code is as follows:

Sports a SEGMENT PARA STACK 'STACK'
The STA DW 64 DUP (0)
TOP EQU $
Sports a ENDS

The DATA SEGMENT
RESULT the DW 0 h
MEM DB 4 DUP (?)
The DATA ENDS

CODES SEGMENT
ASSUME CS: CODES, SS: sports, DS: DATA
START:
The MAIN PROC FAR

MOV AX, sports a
MOV SS, AX
MOV AX, DATA
MOV DS, AX
LEA SP, TOP
XOR AX, AX
MOV DX, 01 h
MOV BL, 02 h
A1: MOV AL, BL
INC BL
The MUL BL
CMP AX, 00 c8h
JA A2
The ADD DX, AX
JMP A1
A2: MOV RESULT, DX
MOV AX, RESULT
CX, MOV 4
MOV DI, 3
L1: PUSH CX
MOV CL, 4
ROL AX, CL
MOV BX, AX
Fh AND BX, 0
The ADD BX, 30 h
JB L2
The ADD BX, 7
L2: MOV MEM (DI), BL
INC DI
POP CX
LOOP L1
LEA DX, MEM
MOV AH, 09 h
INT 21 h
; MOV AH, 8
; INT 21 h
; PUSH DX
MOV AH, 4 ch
INT 21 h
RET
The MAIN ENDP
CODES ENDS
The END START






CodePudding user response:

Online crouching reply ah

CodePudding user response:

Hexadecimal output results, direct look-up table can

HexChars db '0123456789 abcdef'
Then with the results of low 4 a look-up table to its lowest level of character, and then moves to the right four continue to check the results, and so on

CodePudding user response:

Can you give a code?

CodePudding user response:

The model small

.data
HexChars db '0123456789 abcdef'
Buf db 4 dup (0), 'h' $'

The code
Start:
Mov ax, @ data
Mov ds, ax
Mov dx, 038 dh
Cx, mov 4
Lea bx, HexChars
Lea si, buf + 4
I2h: mov ax, dx
And ax, 15
Dec si
Xlat
Mov [si], al
SHR dx, 1
SHR dx, 1
SHR dx, 1
SHR dx, 1
Loop i2h
Mov ah, 9
Mov dx, si
Int 21 h
Mov ah, 4 ch
Int 21 h

The end start
  • Related