Microprocesadores

Páginas: 4 (756 palabras) Publicado: 22 de noviembre de 2012
; this sample gets two numbers from the user,
; then it calculates the sum of these numbers,
; and prints it out.

name "calc"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; these marosare 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 ; skipdeclaration.
s_dcl DB sdat, 0Dh,0Ah, 0

skip_dcl:
LEA SI, s_dcl

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

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

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




org 100h







jmp start ; skip data.

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

msg2 db 0Dh,0Ah, 'enter second number: $'

msg3 db 0Dh,0Ah, 'the sum is: $'

; declaration of variable:
num dw ?

start:


; printfirst 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


callscan_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

;...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Microprocesadores
  • Microprocesador
  • Microprocesadores
  • MICROPROCESADOR
  • Microprocesador
  • Microprocesadores
  • Microprocesador
  • Microprocesadores

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS