La Web del Programador: Comunidad de Programadores
https://www.lawebdelprogramador.com/foros/Ensamblador/1006672-ayuda-con-asembler.html

ayuda con asembler

ayuda con asembler

Publicado por gabriel huett (3 intervenciones) el 02/08/2008 12:03:26
holaa migos... necesito de su ayuda...necesito el codigo fuente para multiplicar 2 numeros de 2 digitos ingresados por teclado y que muestre el resultado por pantalla.

cualquier ayuda seria muy agradecida ya que es para la universidad.

gracias

RE:ayuda con asembler

Publicado por m0skit0 (10 intervenciones) el 02/08/2008 16:22:57
La misma pregunta:

¿Sobre qué plataforma va lo tuyo?

RE:ayuda con asembler

Publicado por gabriel huett (3 intervenciones) el 02/08/2008 17:17:12
windows

RE:ayuda con asembler

Publicado por MSH (120 intervenciones) el 02/08/2008 21:41:48
Saludos.

No esta optimizado, pero funciona

putc macro char
push ax
mov al, char
mov ah, 0eh
int 10h
pop ax
endm

;-----------------------------------------------------------------------------------------------------
.model small
.stack 64h
.data
CR equ 13
LF equ 10
multi1 db 'Introduce primer digito',CR,LF,'$'
multi2 db 'Introduce segundo digito',CR,LF,'$'

dece1 db 0
uni1 db 0
dece2 db 0
uni2 db 0

ten dw 10
num1 db 0
num2 db 0
produ dw ?

resp db 'El resultado es: ',CR,LF,'$'
;-----------------------------------------------------------------------------------------------------
.code
inicio:
mov ax,@data
mov ds,ax
push ds
pop es

call clean ;limpia pantalla
call poscur
;.........................................................................................................................................

mov ah,09h
lea dx,multi1
int 21h

mov ah,08h
int 21h
mov dl,al
xor al,30h
mov dece1,al
mov ah,02h
int 21h


mov ah,08h
int 21h
mov dl,al
xor al,30h
mov uni1,al
mov ah,02h
int 21h

mov ah,02h
mov dl,CR
int 21h
mov ah,02h
mov dl,LF
int 21h
;.................................................................................................................................
mov ah,09h
lea dx,multi2
int 21h
mov ah,08h
int 21h
mov dl,al
xor al,30h
mov dece2,al
mov ah,02h
int 21h

mov ah,08h
int 21h
mov dl,al
xor al,30h
mov uni2,al
mov ah,02h
int 21h
mov ah,02h
mov dl,CR
int 21h
mov ah,02h
mov dl,LF
int 21h
;...........................................................................................................................................
xor ax,ax
xor bx,bx
xor dx,dx

mov al,dece1
mov bx,ten
mul bx
add al,uni1
mov num1,al

;..............................................................................................................................................
xor ax,ax
xor bx,bx
xor dx,dx

mov al,dece2
mov bx,ten
mul bx
add al,uni2
mov num2,al

xor ax,ax
xor bx,bx

mov al,num1
mov bl,num2

mul bx

mov produ,ax

mov ah,09h
lea dx,resp
int 21h

mov ax,produ
call print_num
;...........................................................................................................................................
salir:
mov ax,4c00h
int 21h
;-----------------------------------------------------------------------------------------------------
clean proc
mov ax,0600h
mov bh,07h
mov cx,0000h
mov dx,314fh
int 10h
ret
clean endp
;...........................................................................................................................................
poscur proc
mov ah,02h ;posiciona cursor en columna 0 renglon 0
mov bh,0
mov dh,0
mov dl,0
int 10h
ret
poscur endp
;............................................................................................................................................
print_num proc near

push dx
push ax
cmp ax, 0
jnz not_zero
putc '0'
jmp printed

not_zero:
; the check sign of ax,
; make absolute if it's negative:
cmp ax, 0
jns positive
neg ax
putc '-'

positive:
call print_num_uns
printed:
pop ax
pop dx
ret
print_num endp

; this procedure prints out an unsigned
; number in ax (not just a single digit)
; allowed values are from 0 to 65535 (ffff)
print_num_uns proc near
push ax
push bx
push cx
push dx

; flag to prevent printing zeros before number:
mov cx, 1
; (result of "/ 10000" is always less or equal to 9).
mov bx, 10000 ; 2710h - divider.
; ax is zero?
cmp ax, 0
jz print_zero
begin_print:
; check divider (if zero go to end_print):
cmp bx,0
jz end_print
; avoid printing zeros before number:
cmp cx, 0
je calc
; if ax<bx then result of div will be zero:
cmp ax, bx
jb skip
calc:
mov cx, 0 ; set flag.
mov dx, 0
div bx ; ax = dx:ax / bx (dx=remainder).
; print last digit
; ah is always zero, so it's ignored
add al, 30h ; convert to ascii code.
putc al
mov ax, dx ; get remainder from last div.

skip:
; calculate bx=bx/10
push ax
mov dx, 0
mov ax, bx
div cs: ten ; ax = dx:ax / 10 (dx=remainder).
mov bx, ax
pop ax
jmp begin_print

print_zero:
putc '0'
end_print:
pop dx
pop cx
pop bx
pop ax
ret
print_num_uns endp
end inicio

RE:ayuda con asembler

Publicado por gabriel huett (3 intervenciones) el 02/08/2008 23:58:06
muchisimas gracias... te lo agradesco mucho