Privacidad: Recuerde que la información escrita en los foros de programación es 100% pública y que su ip será registrada asociada a su mensaje. Si encuentra un mensaje fuera de lugar, por favor, notifiquelo para su revisión y eliminación.
calculadora con números sin límite de cifras
Enviado por chinho el día 23 de febrero de 2005
Hola, tengo un pequeño problema. Tengo que hacer un programa con el ensamblador de 80x86, este es una calculadora que realice las operaciones básicas (+, -, / y *) con números sin límite de cifras. No tengo ni idea de ensamblador me estoy leyendo un libro de "Lenguaje ensamblador del 80x86" de Anaya y también he estado mirando algunos ejemplos de programas en ensamblador en internet. Así que si alguien me puede dar una pista de como comenzar a hacer esto, o si tiene algun programa parecido a este hecho se lo agradecería mucho.
Gracias!
Hola amiga espero y si allas encontrado ese programa d ela calcu, oye diskulpa si es k asi fue! me lo podrias prestar, lo k pasa k por = lo necesito y es k no solo basta con k sea en ensamblador si no lo necesito para la Lc3 y pues ojala y me lo puedas prestar, de ante mano mil gracias, cuidate y k estes super bien
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; this maro is copied from emu8086.inc ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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
; define variables:
msg0 db \"note: calculator works with integer values only.\",0Dh,0Ah
db \"to learn how to output the result of a float division see float.asm in examples\",0Dh,0Ah,\'$\'
msg1 db 0Dh,0Ah, 0Dh,0Ah, \'enter first number: $\'
msg2 db \"enter the operator: + - * / : $\"
msg3 db \"enter second number: $\"
msg4 db 0dh,0ah , \'the approximate result of my calculations is : $\'
msg5 db 0dh,0ah ,\'thank you for using the calculator! press any key... \', 0Dh,0Ah, \'$\'
err1 db \"wrong operator!\", 0Dh,0Ah , \'$\'
smth db \" and something.... $\"
; operator can be: \'+\',\'-\',\'*\',\'/\' or \'q\' to exit in the middle.
opr db \'?\'
; first and second number:
num1 dw ?
num2 dw ?
start:
mov dx, offset msg0
mov ah, 9
int 21h
lea dx, msg1
mov ah, 09h ; output string at ds:dx
int 21h
; get the multi-digit signed number
; from the keyboard, and store
; the result in cx register:
call scan_num
; store first number:
mov num1, cx
; new line:
putc 0Dh
putc 0Ah
lea dx, msg2
mov ah, 09h ; output string at ds:dx
int 21h
; get operator:
mov ah, 1 ; single char input to AL.
int 21h
mov opr, al
; new line:
putc 0Dh
putc 0Ah
cmp opr, \'q\' ; q - exit in the middle.
je exit
cmp opr, \'*\'
jb wrong_opr
cmp opr, \'/\'
ja wrong_opr
; output of a string at ds:dx
lea dx, msg3
mov ah, 09h
int 21h
; get the multi-digit signed number
; from the keyboard, and store
; the result in cx register:
call scan_num
; store second number:
mov num2, cx
lea dx, msg4
mov ah, 09h ; output string at ds:dx
int 21h
; calculate:
cmp opr, \'+\'
je do_plus
cmp opr, \'-\'
je do_minus
cmp opr, \'*\'
je do_mult
cmp opr, \'/\'
je do_div
; none of the above....
wrong_opr:
lea dx, err1
mov ah, 09h ; output string at ds:dx
int 21h
exit:
; output of a string at ds:dx
lea dx, msg5
mov ah, 09h
int 21h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; these functions are copied from 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, 0Dh ; carriage return?
JNE not_cr
JMP stop_input
not_cr:
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 (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.