Thursday, March 17, 2011

This program displays the the sum, difference, product, and quotient (with remainder) of two input integers. - By Professor Ronald J. Hart

; Title: CISS 360 Demo Program
;------------------------------------------------------------
; Description: This program displays the the sum, difference,
; product, and quotient (with remainder) of two
; input integers.
;------------------------------------------------------------
; Programmer: Ron Hart
;------------------------------------------------------------
; Date/Time: Tuesday, January 13, 2011 4:11 PM
;------------------------------------------------------------

.586
.MODEL FLAT
INCLUDE console_io.h ; header file for console input/output

.STACK 4096 ; reserve 4096-byte (1024 DWORD) stack

;------------------------------------------------------------
; Input/Output Facility
;------------------------------------------------------------
;
; Macro Operand
;
; put_ch DWORD/Reg (Displays character in parameter)
;
; get_ch None (Loads character from keyboard into EAX)
;
; put_str BYTE (Displays string beginning at given address)
;
; put_i DWORD/Reg (Displays integer value in parameter)
;
; put_fp REAL4/Reg (Displays float value in parameter)
;
; get_i DWORD (Loads integer entered at keyboard into parameter)
;
; get_fp REAL4 (Loads float entered at keyboard into parameter)
;
; get_str BYTE (Loads string entered at keyboard into parameter)
;
;------------------------------------------------------------

.DATA ;****************************************************
;* Data Section *
;****************************************************

prompt1 BYTE "Enter 1st integer: ",0
prompt2 BYTE "Enter 2nd integer: ",0

sum_str BYTE "Sum = ",0
diff_str BYTE "Difference = ",0
prod_str BYTE "Product = ",0
quot_str BYTE "Quotient = ",0
rem_str BYTE "Remainder = ",0

value1 DWORD ?
value2 DWORD ?
newline DWORD 10

.CODE ;****************************************************
;* Code Section *
;****************************************************

_MainProc PROC ; start of main program

;;-------------------------------------------------------
;; Prompt for input integer values
;;-------------------------------------------------------
put_str prompt1 ; prompt for first integer value
get_i value1 ; get first integer value
put_ch newline ; output newline
put_ch newline ; output another newline
put_str prompt2 ; prompt for second integer value
get_i value2 ; get second integer value
put_ch newline ; output newline
put_ch newline ; output another newline
;;-------------------------------------------------------
;; Addition
;;-------------------------------------------------------
mov eax, value1 ; load EAX with first integer value
add eax, value2 ; add second integer value to EAX
put_str sum_str ; display "sum" string
put_i eax ; display sum of two integer values
put_ch newline ; output newline
put_ch newline ; output another newline
;;-------------------------------------------------------
;; Subtraction
;;-------------------------------------------------------
mov eax, value1 ; load EAX with 1st integer value
sub eax, value2 ; EAX = EAX - 2nd integer value
put_str diff_str ; display "difference" string
put_i eax ; display difference of two integer values
put_ch newline ; output newline
put_ch newline ; output another newline
;;-------------------------------------------------------
;; Multiplication
;;-------------------------------------------------------
mov eax, value1 ; load EAX with 1st integer value
imul eax, value2 ; EAX = EAX * 2nd integer value
put_str prod_str ; display "product" string
put_i eax ; display product of two integer values
put_ch newline ; output newline
put_ch newline ; output another newline
;;-------------------------------------------------------
;; Division
;;-------------------------------------------------------
mov eax, value1 ; dividend to EAX
cdq ; prepare EDX for division
idiv value2 ; divide EDX:EAX by divisor (value2)
put_str quot_str ; display "quotient" string
put_i eax ; display quotient of two integer values
put_ch newline ; output newline
put_str rem_str ; display "remainder" string
put_i edx ; display remainder after division of two integer values
;;-------------------------------------------------------
put_ch newline ; output newline
put_ch newline ; output newline
done ; macro to display "done" message and get any key
xor eax, eax ; exit with return code 0
ret ; return

_MainProc ENDP ; end of main program

;------------------------------------------------------------

proc_name PROC ; sample procedure

push ebp ; save base pointer
mov ebp, esp ; establish stack frame

;; push registers used by this proc

;; proc code inserted here

;; pop registers used by this proc

pop ebp ; restore base pointer

ret

proc_name ENDP

;----------------------------------------------------------------------

stat_flag MACRO

fstsw ax ; FPU status word to AX
sahf ; condition code bits to flags
ENDM

;----------------------------------------------------------------------

END ; end of source code

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.