Microsoft (R) Macro Assembler Version 6.14.8444 11/28/17 13:13:49 mult: per esercitazione Calcolatori 28/11/2017 Page 1 - 1 TITLE mult: per esercitazione Calcolatori 28/11/2017 comment * Vari modi per moltiplicare due numeri in assembler 8086. data creazione: 5 dicembre 2016 ultima revisione: 28 novembre 2017 * ;----------------------------------------------------------------- ; Definizione costanti = 000D CR EQU 13 ; carriage return = 000A LF EQU 10 ; line feed = 0024 DOLLAR EQU '$' ;----------------------------------------------------------------- ; M A C R O ;----------------------------------------------------------------- display macro xxxx ; N.B. ogni stringa deve terminare con '$' push dx push ax mov dx,offset xxxx mov ah,9 int 21h pop ax pop dx endm ;----------------------------------------------------------------- ; 0000 PILA SEGMENT STACK 'STACK' ; definizione del segmento di stack 0000 0040 [ DB 64 DUP('STACK') ; lo stack e' riempito con la stringa 'stack' 53 54 41 43 4B ] ; per identificarlo meglio in fase di debug 0140 PILA ENDS ;----------------------------------------------------------------- ; 0000 DATI SEGMENT PUBLIC 'DATA' ; definizione del segmento dati 0000 0D 0A 24 CRLF db CR,LF,DOLLAR 0003 3A 24 SEP db ':',DOLLAR 0005 20 78 20 24 TIMES db ' x ',DOLLAR 0009 20 3D 20 24 EQUAL db ' = ',DOLLAR 000D 75 73 6F 20 64 65 messaggio1 db "uso della istruzione MUL : ",DOLLAR 6C 6C 61 20 69 73 74 72 75 7A 69 6F 6E 65 20 4D 55 4C 20 3C 6F 70 3E 3A 20 20 24 002E 7B moltiplicando db 123 002F CC moltiplicatore db 204 0030 0000 prodotto dw ? ; per conversione del risultato in ASCII e stampa a video = 0010 max_strlen equ 16 0032 0010 [ stringa_ax db max_strlen dup (?),' $' 00 ] 20 24 0044 DATI ENDS ;================================================================= 0000 CSEG1 SEGMENT PUBLIC 'CODE' 0000 MAIN proc far ASSUME CS:CSEG1,DS:DATI,SS:PILA,ES:NOTHING; 0000 B8 ---- R MOV AX,SEG DATI 0003 8E D8 MOV DS,AX ;****** 1. USO DELL'ISTRUZIONE 8086 'MUL' ***** 0005 8A 16 002E R mov dl, moltiplicando 0009 8A 1E 002F R mov bl, moltiplicatore ; stampa a video operandi ; [...] 0047 8A C2 mov al,dl 0049 F6 E3 mul bl ; mul operando <===> ax <--- al*operando 004B A3 0030 R mov prodotto,ax ; stampa a video risultato 004E E8 004F call near ptr display_ax ; [...] 005C exit: 005C B4 4C MOV AH,4CH ; ritorno al DOS 005E CD 21 INT 21H 0060 main endp ; routine di conversione di un numero a 16 bit (il cui valore e' posto nello stack) ; nell'equivalente in base 10, espresso in ASCII e posto ; in una stringa di N caratteri, il cui indirizzo e' anch'esso inserito nello stack ; prima della chiamata. Il valore di ritorno N e' restituito al chiamante attraverso ; lo stack ; 0060 bin2decascii proc near 0060 50 push ax 0061 53 push bx 0062 51 push cx 0063 52 push dx 0064 56 push si 0065 57 push di 0066 55 push bp 0067 9C pushf 0068 8B EC mov bp,sp 006A 83 C5 10 add bp,16 ; rimuove l'effetto dei push qui sopra 006D 8B 46 06 mov ax,SS:[bp+6] ; numero da convertire (e' sepolto sotto 3 words) 0070 BB 000A mov bx,10 ; la conversione e' da base 2 a base 10 0073 B9 0000 mov cx,0 0076 33 D2 again: xor dx,dx 0078 F7 F3 div bx ; in DX il resto, in AX il quoziente di [DX:AX]/[BX] 007A 80 CA 30 or dl,30h ; si rende ASCII la cifra decimale 007D 32 F6 xor dh,dh 007F 52 push dx 0080 41 inc cx 0081 83 F8 00 cmp ax,0 0084 74 02 je save_result 0086 EB EE jmp again 0088 save_result: 0088 BF 0000 mov di,0 008B 8B 5E 04 mov bx,[bp+4] ; offset della stringa destinazione 008E 5A cycle: pop dx 008F 88 11 mov [bx][di],dl 0091 47 inc di 0092 E2 FA loop cycle 0094 89 7E 02 mov [bp+2],di ; numero di caratteri nella stringa destinazione 0097 9D popf 0098 5D pop bp 0099 5F pop di 009A 5E pop si 009B 5A pop dx 009C 59 pop cx 009D 5B pop bx 009E 58 pop ax 009F C3 ret 00A0 bin2decascii endp ; routine di conversione e stampa a video formattata ; di un numero intero non negativo posto nel registro AX ; 00A0 display_ax proc near 00A0 50 push ax 00A1 53 push bx 00A2 50 push ax 00A3 B8 0032 R mov ax,offset stringa_ax 00A6 50 push ax 00A7 B8 000A mov ax,10 ; si inserisce un dato qualsiasi a 16 bit nello stack per fare 00AA 50 push ax ; posto al valore N di ritorno fornito dalla procedura 00AB E8 FFB2 call near ptr bin2decascii 00AE 5B pop bx ; in bx il numero di caratteri della stringa 00AF 83 C4 04 add sp,4 00B2 C6 87 0032 R 24 mov stringa_ax[bx],'$' ; $ per poter stampare display stringa_ax 00B7 52 1 push dx 00B8 50 1 push ax 00B9 BA 0032 R 1 mov dx,offset stringa_ax 00BC B4 09 1 mov ah,9 00BE CD 21 1 int 21h 00C0 58 1 pop ax 00C1 5A 1 pop dx 00C2 5B pop bx 00C3 58 pop ax 00C4 C3 ret 00C5 display_ax endp 00C5 cseg1 ends END MAIN ; il programma comincia all'indirizzo di MAIN Microsoft (R) Macro Assembler Version 6.14.8444 11/28/17 13:13:49 mult: per esercitazione Calcolatori 28/11/2017 Symbols 2 - 1 Macros: N a m e Type display . . . . . . . . . . . . Proc Segments and Groups: N a m e Size Length Align Combine Class CSEG1 . . . . . . . . . . . . . 16 Bit 00C5 Para Public 'CODE' DATI . . . . . . . . . . . . . . 16 Bit 0044 Para Public 'DATA' PILA . . . . . . . . . . . . . . 16 Bit 0140 Para Stack 'STACK' Procedures, parameters and locals: N a m e Type Value Attr MAIN . . . . . . . . . . . . . . P Far 0000 CSEG1 Length= 0060 Public exit . . . . . . . . . . . . . L Near 005C CSEG1 bin2decascii . . . . . . . . . . P Near 0060 CSEG1 Length= 0040 Public again . . . . . . . . . . . . L Near 0076 CSEG1 save_result . . . . . . . . . L Near 0088 CSEG1 cycle . . . . . . . . . . . . L Near 008E CSEG1 display_ax . . . . . . . . . . . P Near 00A0 CSEG1 Length= 0025 Public Symbols: N a m e Type Value Attr CRLF . . . . . . . . . . . . . . Byte 0000 DATI CR . . . . . . . . . . . . . . . Number 000Dh DOLLAR . . . . . . . . . . . . . Number 0024h EQUAL . . . . . . . . . . . . . Byte 0009 DATI LF . . . . . . . . . . . . . . . Number 000Ah SEP . . . . . . . . . . . . . . Byte 0003 DATI TIMES . . . . . . . . . . . . . Byte 0005 DATI max_strlen . . . . . . . . . . . Number 0010h messaggio1 . . . . . . . . . . . Byte 000D DATI moltiplicando . . . . . . . . . Byte 002E DATI moltiplicatore . . . . . . . . . Byte 002F DATI prodotto . . . . . . . . . . . . Word 0030 DATI stringa_ax . . . . . . . . . . . Byte 0032 DATI 0 Warnings 0 Errors