Docsity

Computer Organization and Programming - Lab Problem 1 | COSC 2410, Lab Reports of Computer Architecture and Organization

Toggle sidebar
bg1
COSC 2410: Lab Problem #1 Name:_________________________
Dr. Mirkovic, Spring 2004
Due: 2/17/2004
Part I – Programming
You will create a program that will compute the arithmetic result of addition, subtraction,
multiplication, and division. The program is to be broken into two parts: arithmetic practice, and
temperature conversion.
In the first part of the program you are to prompt the user for two numbers. With these numbers,
you will: compute the addition and display the result, subtract these two numbers and display the
result, multiply these two numbers and display the result, and finally divide these two numbers and
display the result. You should display the result the preceding order and each result should be
labeled with some output indicating what type of arithmetic operation was performed.
In the second apart you will again prompt the user for a Fahrenheit temperature. With this
temperature acquired, you will convert it to its Celsius equivalent and display the result (indicate in
the output that the result is the Celsius equivalent). The conversion formula from Fahrenheit to
Celsius is as follows:
Celsius = (Fahrenheit – 32) * 5/9
You then need to compute the Kelvin temperature equivalent and display the result to standard out
(indicate in the output that the result is the Kelvin equivalent). The conversion formula from
Fahrenheit to Celsius is as follows:
Kelvin = (Fahrenheit – 32) * 5/9 + 273
You may use any functions from the “util.lib,” file. You will need to use “PutDec,” to display
numbers to standard out and the function “GetDec,” to acquire input from the user. You can use the
aforementioned functions by adding an external definition to you program. You do with the syntax,
EXTERN <FUNCTION NAME>:<QUALIFIED TYPE>. For example for the function “GetDec,”
you would add the extern line in a location that is above the elaboration of all functions that use that
externally defined function (you only need have declared the external function once). The
<QUALIFIED TYPE> in this case would be the type of pointers that are used for this function and
should be “NEAR.” The following demonstrates
EXTERN GetDec:near
The external declaration of the function name is case sensitive and usually follows the C language
standards unless otherwise specified.
pf3
pf4
pf5

Partial preview of the text

Download Computer Organization and Programming - Lab Problem 1 | COSC 2410 and more Lab Reports Computer Architecture and Organization in PDF only on Docsity!

COSC 2410: Lab Problem #1 Name:_________________________

Dr. Mirkovic, Spring 2004 Due: 2/17/

Part I – Programming

You will create a program that will compute the arithmetic result of addition, subtraction,

multiplication, and division. The program is to be broken into two parts: arithmetic practice, and

temperature conversion.

In the first part of the program you are to prompt the user for two numbers. With these numbers,

you will: compute the addition and display the result, subtract these two numbers and display the

result, multiply these two numbers and display the result, and finally divide these two numbers and

display the result. You should display the result the preceding order and each result should be

labeled with some output indicating what type of arithmetic operation was performed.

In the second apart you will again prompt the user for a Fahrenheit temperature. With this

temperature acquired, you will convert it to its Celsius equivalent and display the result (indicate in

the output that the result is the Celsius equivalent). The conversion formula from Fahrenheit to

Celsius is as follows:

Celsius = (Fahrenheit – 32) * 5/

You then need to compute the Kelvin temperature equivalent and display the result to standard out

(indicate in the output that the result is the Kelvin equivalent). The conversion formula from

Fahrenheit to Celsius is as follows:

Kelvin = (Fahrenheit – 32) * 5/9 + 273

You may use any functions from the “util.lib,” file. You will need to use “PutDec,” to display

numbers to standard out and the function “GetDec,” to acquire input from the user. You can use the

aforementioned functions by adding an external definition to you program. You do with the syntax,

EXTERN :. For example for the function “GetDec,”

you would add the extern line in a location that is above the elaboration of all functions that use that

externally defined function (you only need have declared the external function once). The

in this case would be the type of pointers that are used for this function and

should be “NEAR.” The following demonstrates

EXTERN GetDec:near

The external declaration of the function name is case sensitive and usually follows the C language

standards unless otherwise specified.

The input will be positive numbers as well as negative numbers, therefore, use the appropriate

arithmetic operators.

Grade distribution:

Part 1

Addition 10%

Subtraction 10%

Multiplication 10%

Division 10%

Fahrenheit Conversion

Celsius 10%

Kelvin 10%

Part 2 10%

Following Instructions 10%

Comments

Program Description 5%

Code Comments 5%

Misc./Efficiency 10%

Part II – Questions and Answers

1) Run your program 4 times and fill in the table with the given input

Input Output

st

num 2

nd

num Add Subtract Multiply Divide

0 0 0 0 0 Undefined

Input Output

Fahrenheit Celsius Kelvin

2) Convert the following numbers from one number system to the next (<#>b means # in base

number system b, i.e. 10 2 is 10 in the binary number system or 2 in the decimal number system)

a. 32 10 to binary = 2

b. 101001012 to hexidecimal = 0A5 16

c. 10100101 2 to octal = 245 8

d. FFE5 16 to binary = 1111 1111 1110 0101 2

e. 43 10 to base 7 = 61 7

mess3 db "Result of addition:" len3 equ lengthof mess3 ;get length of message mess4 db "Result of subtraction:" len4 equ lengthof mess4 ;get length of message mess5 db "Result of multiplication:" len5 equ lengthof mess5 ;get length of message mess6 db "Result of division:" len6 equ lengthof mess6 ;get length of message mess7 db "Enter farenheiht measurement:" len7 equ lengthof mess7 ;get length of message mess8 db "Celsius equiv:" len8 equ lengthof mess8 ;get length of message mess9 db "Kelvin equiv:" len9 equ lengthof mess9 ;get length of message

first sword? second sword?

.code ;begin the code segment

;************************************************* ;Function prototypes ;************************************************* extern GetDec:near, PutDec:near displaymesg proto near c m:word,l:byte

main proc .startup ;start the main procedure @Cls ;clear the screen @SetCsrPos 0, 0 ;set the cursor position

;PART I ;************************************************* ;Get the first number ;************************************************* invoke displaymesg, addr mess1, len1 ;display mess call getdec ;get first number from stdin mov first, ax ;store the number to variable first

;************************************************* ;Get the second number ;************************************************* invoke displaymesg, addr mess2, len2 ;display mess call getdec ;get second number from stdin mov second, ax ;store the number to variable second invoke displaymesg, addr crlf, lencrlf ;display crlf

;************************************************* ;Display first+second ;************************************************* invoke displaymesg, addr mess3, len3 ;display mess mov ax, first ;move first into AX register mov bx, second ;move second into BX register add ax, bx ;add AX and BX, store in AX call putdec ;display AX register to stdout (addition) invoke displaymesg, addr crlf, lencrlf ;display crlf

;************************************************* ;Display first-second ;************************************************* invoke displaymesg, addr mess4, len4 ;display mess mov ax, first ;move first into AX register mov bx, second ;move second into BX register sub ax, bx ;subtract BX from AX, store in AX call putdec ;display AX register to stdout (subtraction) invoke displaymesg, addr crlf, lencrlf ;display crlf

;************************************************* ;Display first*second ;************************************************* invoke displaymesg, addr mess5, len5 ;display mess

mov dx, 0 ;clear DX mov ax, first ;move first into AX register mov bx, second ;move second into BX register imul bx ;multiply AX and BX, store in AX call putdec ;display AX register to stdout (multiplication) invoke displaymesg, addr crlf, lencrlf ;display crlf

;************************************************* ;Display first/second ;************************************************* invoke displaymesg, addr mess6, len6 ;display mess mov ax, first ;move first into AX register mov bx, second ;move second into BX register idiv bx ;divide AX by BX, store in AX call putdec ;display AX register to stdout (division) invoke displaymesg, addr crlf, lencrlf ;display crlf invoke displaymesg, addr crlf, lencrlf ;display crlf

;PART II ;************************************************* ;Get the farenheit number ;************************************************* invoke displaymesg, addr mess7, len7 ;display mess call getdec ;get farenheit number from stdin sub ax, celsiusconst ;subtrack celsius constant from AX mov dx, 0 ;clear DX mov bx, 5 ;move 5 into BX imul bx ;signed multiply AX by BX mov bx, 9 ;move 9 into BX idiv bx ;signed divide AX by BX invoke displaymesg, addr mess8, len8 ;display mess call putdec ;display AX register to stdout (celsius) invoke displaymesg, addr crlf, lencrlf ;display crlf add ax, kelvinconst ;add kelvinconst to AX invoke displaymesg, addr mess9, len9 ;display mess call putdec ;display AX register to stdout (kelvin) invoke displaymesg, addr crlf, lencrlf ;display crlf .exit ;end the main procedure main endp

;************************************************* ;Function: displaymesg ;Description: ; This function takes a pointer to a string ; as input and the length of the string and ; prints the result to stdout. It does this ; by using the OS int 21h and function 040h. ; BX holds the device (1), cl holds the ; length of string, dx holds the address of ; the string to be displayed. Flags and ; the 32-bit registers are pushed and popped ; of the stack. ;Input: ; m - a pointer to the string which is to be ; displayed to stdout ; l - an short integer indicating the length ; of the string to display ;Output: ; None ;Return: ; None ;************************************************* displaymesg proc near c uses ax bx cx dx, m:word,l:byte pushf ;push the flags onto the stack pushad ;save all registers on the stack mov ah, 040h ;move function number 040h into ah mov bx, 1 ;move device number into bx mov cl, l ;move the length of the message into cx shl ch, 8 ;clear out high part of cx mov dx, m ;move the message address into dx int 21h ;request interrupt service from OS