計算器32位在8086組裝32位計算器
有人可以幫助我與我的32位計算器在MASM32。我認爲加法和減法是好的,但我不能打印十進制數字;
0002FFFF - 10005 = 1fffa
在MEMORY:0001 0FFFA
PRINTING:165530十進制
DATA_HERE SEGMENT
mult1 dw 0002H
dw 0FFFFH
mult2 dw 0001H
dw 0005H
ans dw 0,0
DATA_HERE ENDS
STACK_HERE SEGMENT STACK
DW 40 DUP(0)
STACK_HERE ENDS
CODE_HERE SEGMENT
ASSUME CS:CODE_HERE, DS:DATA_HERE, SS: STACK_HERE
INICIO:
MOV AX,DATA_HERE
MOV DS,AX
ADD:
MOV AX,mult1+2 ; take lower 16-bit of NUM1; take
ADD AX,mult2+2 ; AX = AX + lower 16-bit of NUM2
MOV ans+2,AX ; Store lower 16-bit result at ans
MOV AX,mult1 ; take higher 16-bit of NUM1 in AX;
ADC AX,mult2 ; AX = AX + NUM2 + CF (add with carry)
MOV ans,AX ; Store higher 16-bit result at ans
SUBTRACT:
MOV AX,mult1+2 ; take lower 16-bit of NUM1 in AX ;
SUB AX,mult2+2 ; AX = AX - lower 16-bit of NUM2
MOV ans+2,AX ; Store lower 16-bit result at ans
MOV AX,mult1 ; take higher 16-bit of NUM1 in AX;
SUB AX,mult2 ; AX = AX - NUM2
MOV ans,AX ; Store higher 16-bit result at ans
xor si,si
mov si,0
ciclo:
mov AX, ans[si];
call display ; print AX
add si, 2
cmp si, 2
JLE ciclo
mov ax,4C00h
int 21h
display proc
;push CX
;Beginning of procedure
MOV BX, 10 ;Initializes divisor
;MOV DX, 0000H ;Clears DX
MOV CX, 0000H ;Clears CX
;Splitting process starts here
.Dloop1:
MOV DX, 0000H ;Clears DX during jump
DIV BX ;Divides AX by BX
PUSH DX ;Pushes DX(remainder) to stack
INC CX ;Increments counter to track the number of digits
CMP AX, 0 ;Checks if there is still something in AX to divide
JNE .Dloop1 ;Jumps if AX is not zero
.Dloop2: POP DX ;Pops from stack to DX
ADD DX, 30H ;Converts to it's ASCII equivalent
MOV AH, 02H
INT 21H ;calls DOS to display character
LOOP .Dloop2 ;Loops till CX equals zero
;pop CX
RET ;returns control
display ENDP
CODE_HERE ENDS
END INICIO
顯然,你不能單獨打印這兩個部分的小數。你可以創建一個32位的分隔符或者使用不同的方法,比如重複減去10的冪。 – Jester
如果你能找到一箇舊的自發裝配書/庫的副本,那裏有你可以使用的預先構建的宏。 –
對於之前的嘗試(您理解^ _),我表示歉意,這是最終版本,適用於任何32位數字,從0到FFFFFFFFh。 –