Сейчас я изучаю ассемблер, и мне пришлось написать код, который умножает два числа на два (например, 23 * 45 = 1035), но мне нужно прочитать каждое число в другой регистр (например, 2 переходит к ah
и 3 идет к al
.. например). Сейчас я увидел в сети инструкцию aam
, но мне не удается использовать ее в своем коде, мне нужна помощь и объяснение, как правильно ее использовать.
.MODEL small ;DS <= 64KB, CS <= 64KB
.STACK 100h
.DATA
msg1 db 13,10,'Enter two numbers: $'
msg2 db 13,10,'Invalid value$'
msg3 db 13,10,' * = $'
msg4 db 13,10,'Hit every key to exit$'
dig1 db 0
dig2 db 0
dig3 db 0
dig4 db 0
char1 db 0
char2 db 0
result1 db 0
result2 db 0
result3 db 0
result4 db 0
crlf db 13,10,'$'
.CODE
mov AX, @data
mov DS, AX
main:
lea DX, msg1 ;Show msg1
mov AH, 09h ;AH=9 - "print string" sub function
int 21h ;call DOS services
;Reading the numbers
mov AH, 01h ;Read first character
int 21h
mov dig1, AL
cmp dig1, '0' ;If character less than 0 - invalid
jb invalid ;JB - Jump if Beneath
cmp dig1, '9' ;if character greater than 9 - invalid
ja invalid ;JA - Jump if Above
mov AH, 01h ;Read second character
int 21h
mov dig2, AL
cmp dig2, '0' ;If character less than 0 - invalid
jb invalid ;JB - Jump if Beneath
cmp dig2, '9' ;if character greater than 9 - invalid
ja invalid ;JA - Jump if Above
mov AH, 02h ;space between the number
mov DL, ' '
int 21h
mov AH, 01h ;Read third character
int 21h
mov dig3, AL
cmp dig3, '0' ;If character less than 0 - invalid
jb invalid ;JB - Jump if Beneath
cmp dig3, '9' ;if character greater than 9 - invalid
ja invalid ;JA - Jump if Above
mov AH, 01h ;Read fouth character
int 21h
mov dig4, AL
cmp dig4, '0' ;If character less than 0 - invalid
jb invalid ;JB - Jump if Beneath
cmp dig4, '9' ;if character greater than 9 - invalid
ja invalid ;JA - Jump if Above
;check if the promgram ends
mov CL, dig1
add CL, dig2
add CL, dig3
add CL, dig4
cmp CL, 192
je exit
;calculating the numbers
mov CX, 0
sub dig1,'0'
sub dig2,'0'
sub dig3,'0'
sub dig4,'0'
mov AL,dig1 ;make dig1 tenth
mov BL,10
mul BL
add AL,dig2
mov char1,AL ;making char1 the first num
mov AL,dig3 ;make dig3 tenth
mov BL,10
mul BL
add AL,dig4
mov char2,AL ;making char2 the second num
mov AL, char1
mov BL, char2
mul BL
mov DX,0 ;on mul/div with 16bit must clean DX
mov BX, 1000
div BX ;On 16bit: AX=result , DX=remainder
mov CX, DX
mov result1, AL
mov BL, 100
mov AX, CX
div BL
mov result2, AL
mov CL, AH ;On 8bit: AL=result , AH=remainder
mov BL, 10
mov AH, 0
mov AL, CL
div BL
mov result3, AL
mov result4, AH
add dig1,'0'
add dig2,'0'
add dig3,'0'
add dig4,'0'
add result1,'0'
add result2,'0'
add result3,'0'
add result4,'0'
;printing the result
lea DX, crlf ;New line
mov AH, 09h
int 21h
lea BX, msg3 ;Place msg3's address in BX
mov AL, dig1 ;Put first number in AL
mov [BX + 2], AL ;Put first number in msg3
mov AL, dig2 ;Put second number in AL
mov [BX + 3], AL ;Put second number in msg3
mov AL, dig3 ;Put third number in AL
mov [BX + 5], AL ;Put third number in msg3
mov AL, dig4 ;Put fourth number in AL
mov [BX + 6], AL ;Put fourth number in msg3
mov AL, result1 ;Put first number of result in AL
mov [BX + 8], AL ;Put first number of result in msg3
mov AL, result2 ;Put second number of result in AL
mov [BX + 9], AL ;Put second number of result in msg3
mov AL, result3 ;Put third number of result in AL
mov [BX + 10], AL ;Put third number of result in msg3
mov AL, result4 ;Put fourth number of result in AL
mov [BX + 11], AL ;Put fourth number of result in msg3
lea DX, msg3 ;Show msg3
mov AH, 09h
int 21h
jmp main
invalid:
lea DX, msg2 ;Show msg2
mov AH, 09h
int 21h
jmp main
exit:
lea DX, msg4 ;Show msg4
mov AH, 09h
int 21h
mov AH, 01h ;Read a character
int 21h
mov AH, 4Ch ;Kill the program
int 21h
END