Ensamblador - calculadora en ensamblador

 
Vista:

calculadora en ensamblador

Publicado por kaito (1 intervención) el 14/04/2005 17:12:41
hola me estaria muy agradecido si pudieran ayudarme con los siguientes programas ya que no se realizarlos:

Diseñar un programa que muestre el siguiente menú en pantalla

C:>menú.exe
Menú de opciones

1.Cálculo de la suma
2.Cálculo del factorial
3.Cálculo del producto
4.Salir de la calculadora

Cuando el usuario pulsa alguna de estas opciones, se piden los operandos necesarios y se muestra el resultado, volviendo a mostrarse el menú hasta que el usuario pulse la opción 4.

y este otro:

Diseñe un programa que a partir de un valor almacenado en el registro DX, lo traduzca a ASCII y lo imprima en pantalla.

C:>inverso.exe
Resultado:456

C:>inverso.exe
Resultado:-37


Les estare muy agradecidos a quienes me lo puedan solucionar, mi email es [email protected]
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:calculadora en ensamblador

Publicado por Walter Blanco (4 intervenciones) el 29/08/2005 16:43:29
Espero te sirva este es el codigo para la suma de dos numeros ingresados por teclado. Luego el resultado es impreso en pantalla.

En este momento no tengo tiempo de pasate este ejemplo a español, pero funciona muy bien. Espero te sirva.

; este ejemplo toma dos numero del usuario
; y calcula la suma de los dos numeros.
; luego imprime la salida.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; these maros are copied from emu8086.inc ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; this macro prints a string that is given as a parameter, example:
; PRINTN 'hello world!'
; the same as PRINT, but new line is automatically added.
PRINTN MACRO sdat
LOCAL next_char, s_dcl, printed, skip_dcl

PUSH AX ; store registers...
PUSH SI ;

JMP skip_dcl ; skip declaration.
s_dcl DB sdat, 13, 10, 0

skip_dcl:
LEA SI, s_dcl

next_char:
MOV AL, CS:[SI]
CMP AL, 0
JZ printed
INC SI
MOV AH, 0Eh ; teletype function.
INT 10h
JMP next_char
printed:

POP SI ; re-store registers...
POP AX ;
ENDM

; this macro prints a char in AL and advances
; the current cursor position:
PUTC MACRO char
PUSH AX
MOV AL, char
MOV AH, 0Eh
INT 10h
POP AX
ENDM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

org 100h

jmp start ; skip data.

msg1 db 13, 10, 'input numbers in this range: [-32768..32767]', 13, 10
db 13, 10, 'enter first number: $'

msg2 db 13, 10, 'enter second number: $'

msg3 db 13, 10, 'the sum is: $'

; declaration of variable:
num dw ?

start:

; print first message
mov dx, offset msg1
mov ah, 9
int 21h

call scan_num

; keep first number:
mov num, cx

; print second message
mov dx, offset msg2
mov ah, 9
int 21h

call scan_num

; add numbers:
add num, cx
jo overflow

; print the result:
mov dx, offset msg3
mov ah, 9
int 21h

mov ax, num
call print_num

jmp exit

; process overlow error:
overflow:

printn 'we have overflow!'

exit:

; wait for any key press:
mov ah, 0
int 16h

ret ; return control to operating system.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; estas funciones son copiadas del emu8086.inc ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; gets the multi-digit SIGNED number from the keyboard,
; and stores the result in CX register:
SCAN_NUM PROC NEAR
PUSH DX
PUSH AX
PUSH SI

MOV CX, 0

; reset flag:
MOV CS:make_minus, 0

next_digit:

; get char from keyboard
; into AL:
MOV AH, 00h
INT 16h
; and print it:
MOV AH, 0Eh
INT 10h

; check for MINUS:
CMP AL, '-'
JE set_minus

; check for ENTER key:
CMP AL, 13 ; carriage return?
JNE not_cr
JMP stop_input
not_cr:

CMP AL, 8 ; 'BACKSPACE' pressed?
JNE backspace_checked
MOV DX, 0 ; remove last digit by
MOV AX, CX ; division:
DIV CS:ten ; AX = DX:AX / 10 (DX-rem).
MOV CX, AX
PUTC ' ' ; clear position.
PUTC 8 ; backspace again.
JMP next_digit
backspace_checked:

; allow only digits:
CMP AL, '0'
JAE ok_AE_0
JMP remove_not_digit
ok_AE_0:
CMP AL, '9'
JBE ok_digit
remove_not_digit:
PUTC 8 ; backspace.
PUTC ' ' ; clear last entered not digit.
PUTC 8 ; backspace again.
JMP next_digit ; wait for next input.
ok_digit:

; multiply CX by 10 (first time the result is zero)
PUSH AX
MOV AX, CX
MUL CS:ten ; DX:AX = AX*10
MOV CX, AX
POP AX

; check if the number is too big
; (result should be 16 bits)
CMP DX, 0
JNE too_big

; convert from ASCII code:
SUB AL, 30h

; add AL to CX:
MOV AH, 0
MOV DX, CX ; backup, in case the result will be too big.
ADD CX, AX
JC too_big2 ; jump if the number is too big.

JMP next_digit

set_minus:
MOV CS:make_minus, 1
JMP next_digit

too_big2:
MOV CX, DX ; restore the backuped value before add.
MOV DX, 0 ; DX was zero before backup!
too_big:
MOV AX, CX
DIV CS:ten ; reverse last DX:AX = AX*10, make AX = DX:AX / 10
MOV CX, AX
PUTC 8 ; backspace.
PUTC ' ' ; clear last entered digit.
PUTC 8 ; backspace again.
JMP next_digit ; wait for Enter/Backspace.


stop_input:
; check flag:
CMP CS:make_minus, 0
JE not_minus
NEG CX
not_minus:

POP SI
POP AX
POP DX
RET
make_minus DB ? ; used as a flag.
SCAN_NUM ENDP

; this procedure prints number in AX,
; used with PRINT_NUM_UNS to print signed numbers:
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 (0xFFFF)
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


ten DW 10 ; used as multiplier/divider by SCAN_NUM & PRINT_NUM_UNS.

Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:calculadora en ensamblador

Publicado por maitane (2 intervenciones) el 10/05/2006 11:45:52
ola!!! somos dos chicas q necesitamos el codigo de una calculadora en mplab 7.2 e igual nos podrias ayudar.nos jugamos el curso y lo necesitamos en menos de un mes.
gracias
besos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:calculadora en ensamblador

Publicado por Sergio (1 intervención) el 18/04/2007 15:38:11
hola quiero decirles que estudien y piensen un poco más, brutas.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:calculadora en ensamblador

Publicado por cristian (2 intervenciones) el 19/10/2007 18:46:43
espero que fuciones bien
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:calculadora en ensamblador

Publicado por cristian (2 intervenciones) el 19/10/2007 18:56:34
hola estare muy agradecido al que me pueda hacer llegar un programa que me sume diferentes numeros ingresados por un teclado al pic 16f84 y me lo muestre en un lcd

espero que alguien me solucione este gran problemita que tengo
mi correo es [email protected]
gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar