有人会给我一个microASM程序,它将乘以用户给出的2个值吗?我正在为我的参考资料做一些研究。
更新:这是我尝试的代码,但它通过了无穷大
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
DATA SEGMENT
NUM1 DB ?
NUM2 DB ?
RESULT DB ?
MSG1 DB 10,13,"ENTER FIRST NUMBER: $"
MSG2 DB 10,13,"ENTER SECOND NUMBER: $"
MSG3 DB 10,13,"rESULT OF MULTIPLICATION IS: $"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV NUM1,AL
LEA DX,MSG2
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV NUM2,AL
MUL NUM1
MOV RESULT,AL
AAM
ADD AH,30H
ADD AL,30H
MOV BX,AX
LEA DX,MSG3
MOV AH,9
INT 21H
MOV AH,2
MOV DL,BH
INT 21H
MOV AH,2
MOV DL,BL
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
答案 0 :(得分:0)
好的,Karl Reyes,你要求一个程序来乘以用户给出的两个值。下一个程序正是这样做的。它是用EMU8086制作的,它已被完全评论以帮助您理解它。只需复制,粘贴并运行:
.stack 100h
;------------------------------------------
.data
;------------------------------------------
msj1 db 'Enter first number: $'
str1 db 6 ;MAX NUMBER OF CHARACTERS ALLOWED (4).
db ? ;NUMBER OF CHARACTERS ENTERED BY USER.
db 6 dup (?) ;CHARACTERS ENTERED BY USER.
num1 dw ?
msj2 db 13,10,13,10,'Enter second number: $'
str2 db 6 ;MAX NUMBER OF CHARACTERS ALLOWED (4).
db ? ;NUMBER OF CHARACTERS ENTERED BY USER.
db 6 dup (?) ;CHARACTERS ENTERED BY USER.
num2 dw ?
prod dw ? ;NUM1 * NUM2.
msj3 db 13,10,13,10,'Product : $'
str3 db 7 dup('$')
;------------------------------------------
.code
;INITIALIZE DATA SEGMENT.
mov ax, @data
mov ds, ax
;------------------------------------------
;DISPLAY MESSAGE.
mov ah, 9
mov dx, offset msj1
int 21h
;CAPTURE NUMBER 1 AS STRING.
mov ah, 0Ah
mov dx, offset str1
int 21h
;------------------------------------------
;DISPLAY MESSAGE.
mov ah, 9
mov dx, offset msj2
int 21h
;CAPTURE NUMBER 2 AS STRING.
mov ah, 0Ah
mov dx, offset str2
int 21h
;------------------------------------------
;CONVERT CAPTURED NUMBERS (STRINGS) TO REAL NUMBERS.
mov si, offset str1 ;PARAMETER FOR STRING2NUMBER.
call string2number
mov num1, bx ;RETURNED VALUE.
mov si, offset str2 ;PARAMETER FOR STRING2NUMBER.
call string2number
mov num2, bx ;RETURNED VALUE.
;------------------------------------------
;MULTIPLY.
mov ax, num1
mul num2 ;AX * NUM2. RESULT IN DX:AX.
;------------------------------------------
;DISPLAY RESULT. IGNORE DX, ASSUMING RESULT FITS IN AX.
call number2string ;TAKES AX AS PARAMETER.
mov ah, 9
mov dx, offset msj3
int 21h
mov ah, 9
mov dx, offset str3
int 21h
;------------------------------------------
;WAIT UNTIL USER PRESS ANY KEY.
mov ah,7
int 21h
;------------------------------------------
;FINISH THE PROGRAM PROPERLY.
mov ax, 4c00h
int 21h
;------------------------------------------
;NUMBER TO CONVERT MUST ENTER IN AX.
;ALGORITHM : EXTRACT DIGITS ONE BY ONE, STORE
;THEM IN STACK, THEN EXTRACT THEM IN REVERSE
;ORDER TO CONSTRUCT STRING.
proc number2string
mov bx, 10 ;DIGITS ARE EXTRACTED DIVIDING BY 10.
mov cx, 0 ;COUNTER FOR EXTRACTED DIGITS.
cycle1:
mov dx, 0 ;NECESSARY TO DIVIDE BY BX.
div bx ;DX:AX / 10 = AX:QUOTIENT DX:REMAINDER.
push dx ;PRESERVE DIGIT EXTRACTED FOR LATER.
inc cx ;INCREASE COUNTER FOR EVERY DIGIT EXTRACTED.
cmp ax, 0 ;IF NUMBER IS
jne cycle1 ;NOT ZERO, LOOP.
;NOW RETRIEVE PUSHED DIGITS.
mov si, offset str3
cycle2:
pop dx
add dl, 48 ;CONVERT DIGIT TO CHARACTER.
mov [ si ], dl
inc si
loop cycle2
ret
endp
;------------------------------------------
;CONVERT STRING TO NUMBER IN BX.
;SI MUST ENTER POINTING TO THE STRING.
proc string2number
;MAKE SI TO POINT TO THE LEAST SIGNIFICANT DIGIT.
inc si ;POINTS TO THE NUMBER OF CHARACTERS ENTERED.
mov cl, [ si ] ;NUMBER OF CHARACTERS ENTERED.
mov ch, 0 ;CLEAR CH, NOW CX==CL.
add si, cx ;NOW SI POINTS TO LEAST SIGNIFICANT DIGIT.
;CONVERT STRING.
mov bx, 0
mov bp, 1 ;MULTIPLE OF 10 TO MULTIPLY EVERY DIGIT.
repeat:
;CONVERT CHARACTER.
mov al, [ si ] ;CHARACTER TO PROCESS.
sub al, 48 ;CONVERT ASCII CHARACTER TO DIGIT.
mov ah, 0 ;CLEAR AH, NOW AX==AL.
mul bp ;AX*BP = DX:AX.
add bx,ax ;ADD RESULT TO BX.
;INCREASE MULTIPLE OF 10 (1, 10, 100...).
mov ax, bp
mov bp, 10
mul bp ;AX*10 = DX:AX.
mov bp, ax ;NEW MULTIPLE OF 10.
;CHECK IF WE HAVE FINISHED.
dec si ;NEXT DIGIT TO PROCESS.
loop repeat ;COUNTER CX-1, IF NOT ZERO, REPEAT.
ret
endp
让我知道它是否适合你。