|
Bannato
Iscritto dal: Feb 2003
Messaggi: 947
|
Non hai specificato il sistema operativo, ne la modalita' del processore; ho scelto io DOS/WIN_VM modalita' reale:
Codice:
ENTER_KEY1 EQU 1C0Dh
ENTER_KEY2 EQU 0E00Dh
BACKSPACE_KEY EQU 0E08h
data segment byte 'DATA'
dos_message_1:
DB 'Moltiplicazioni in ASM',0Dh,0Ah,'$'
dos_message_2:
DB 0Dh,0Ah,'Inserire 1° operando: $'
dos_message_3:
DB 0Dh,0Ah,'Inserire 2° operando: $'
dos_message_4:
DB 0Dh,0Ah,0Dh,0Ah,'Risultato: $'
_1st_val_str:
DB 0Ah DUP (?)
_2nd_val_str:
DB 0Ah DUP (?)
_1st_val_bin:
DD ?
_2nd_val_bin:
DD ?
data ends
.386P
.ALPHA
code segment para use16 'CODE'
assume cs:code
Init proc near
push DATA
pop ds
mov dx,OFFSET dos_message_1
call Write_Message
mov dx,OFFSET dos_message_2
call Write_Message
mov si,OFFSET _1st_val_str
call Get_Input
mov di,OFFSET _1st_val_bin
call Str_Dec_To_Bin
mov dx,OFFSET dos_message_3
call Write_Message
mov si,OFFSET _2nd_val_str
call Get_Input
mov di,OFFSET _2nd_val_bin
call Str_Dec_To_Bin
mov dx,OFFSET dos_message_4
call Write_Message
mov eax,ds: dword ptr [_2nd_val_bin]
mul ds: dword ptr [_1st_val_bin]
call Write_Dec_Num64
mov ax,4C00h
int 21h
init endp
;#############################################################################
Get_Input proc near
pusha
xor bx,bx
loop_get_key:
call Get_Key
cmp bx,9h
je test_alt_key
cmp ah,2h
jb test_num_alt
cmp ah,0Bh
ja test_num_alt
test_num_low:
cmp al,'0'
jb test_num_alt
cmp al,'9'
ja test_num_alt
call Write_Char
mov ds: byte ptr [bx+si],al
inc bx
jmp loop_get_key
test_num_alt:
cmp ah,47h
jb test_alt_key
cmp ah,52h
jbe test_num_low
test_alt_key:
cmp ax,BACKSPACE_KEY
jne test_exit
or bx,bx
je loop_get_key
call Get_Cursor_Position
dec dl
call Set_Cursor_Position
dec bx
mov al,' '
call Write_Char
call Set_Cursor_Position
jmp loop_get_key
test_exit:
cmp ax,ENTER_KEY1
je exit_get_input
cmp ax,ENTER_KEY2
jne loop_get_key
exit_get_input:
mov ds: byte ptr [bx+si],0h
popa
ret
Get_Input endp
;#############################################################################
Get_Key proc near
pusha
mov ah,10h
int 16h
mov bp,sp
mov ss: word ptr [bp+0Eh],ax
popa
ret
Get_Key endp
;#############################################################################
Str_Dec_To_Bin proc near
pushad
mov ds: dword ptr [di],0h
call Str_Len
or ax,ax
je exit_str_dec_to_bin
dec ax
xchg ax,bx
xor eax,eax
mov edx,1h
loop_char_str:
movzx ecx,ds: byte ptr [bx+si]
sub cl,'0'
imul ecx,edx
add eax,ecx
imul edx,10d
sub bx,1h
jnc loop_char_str
mov ds: dword ptr [di],eax
exit_str_dec_to_bin:
popad
ret
Str_Dec_To_Bin endp
;#############################################################################
Write_Dec_Num64 proc near
pushad
push eax
push edx
mov edi,0Ah
xor bh,bh
next_dec_long_left:
push eax
mov eax,edx
xor edx,edx
div edi
mov ebp,eax
pop eax
div edi
mov edx,ebp
inc bh
or edx,edx
jne next_dec_long_left
or eax,eax
jne next_dec_long_left
call Get_Cursor_Position
add dl,bh
dec dl
call Set_Cursor_Position
pop edx
pop eax
mov ebx,0Ah
next_dec_long:
push eax
mov eax,edx
xor edx,edx
div ebx
mov ebp,eax
pop eax
div ebx
add dl,'0'
xchg ax,dx
call Write_Char
xchg ax,dx
call Get_Cursor_Position
sub dl,2h
call Set_Cursor_Position
mov edx,ebp
or edx,edx
jne next_dec_long
or eax,eax
jne next_dec_long
popad
ret
Write_Dec_Num64 endp
;#############################################################################
Write_Message proc near
pusha
mov ah,9h
int 21h
popa
ret
Write_Message endp
;#############################################################################
Write_Char proc near
pusha
mov ah,0Eh
int 10h
popa
ret
Write_Char endp
;#############################################################################
Set_Cursor_Position proc near
pusha
mov ah,2h
xor bh,bh
int 10h
popa
ret
Set_Cursor_Position endp
;#############################################################################
Get_Cursor_Position proc near
pusha
mov ah,3h
xor bh,bh
int 10h
mov bp,sp
mov ss: word ptr [bp+0Ah],dx
popa
ret
Get_Cursor_Position endp
Str_Len proc near
push es
push ds
pop es
push cx
push di
mov di,si
mov cx,0FFFFh
xor al,al
repne scasb
not cx
dec cx
xchg ax,cx
pop di
pop cx
pop es
ret
Str_Len endp
code ends
end init
In allegato troverai l'eseguibile. A meno di bug "sembra funzionare" (ho avuto a disposizione poco tempo), non ci sono commente in quanto il sorgente e' autoespicativo, spero ti sia utile a scopo didattico.
|