A program has already been written
to depend on a group of macros; the program is stored in the file p6temp.asm
However, the program will work only if you provide the macros being used.
You are to create seven macros and add them to the file mymacs.inc
so that the program in p6temp.asm can be assembled, linked and executed.
mymacs.inc already has a few macros in it that I am supplying - I already
wrote all the easy ones. The seven macros you are to write are related
and are described below.
gmov dest, source
A macro named GMOV that is a generalization
of the mov instruction. GMOV must allow the source and destination
to be almost anything. GMOV must do the same thing as a mov instruction
for all operands that are valid for mov. But, it must also allow
both the source and destination to be memory references and allow the source
and destination to be any register, including DS, ES, and any of the A
registers. GMOV must be able to move bytes, words, or double
words.
gcmp left, right
A macro named GCMP that is a generalization
of the cmp instruction. GCMP must allow the source and destination
to be almost anything. GCMP must to the same thing as a cmp instruction
for all operands that are valid for cmp. But it must also allow both
the first and second operands to be memory references and allow first and
second to be any register, including DS, ES, and any of the A registers.
GCMP must be able to compare bytes, words, or double words.
smov dest, source
A macro named SMOV that copies a null
terminated string from the source to the destination. Both source
and destination are required to be memory references (variable names).
add2 dest, source
sub2 dest, source
Macros named ADD2 and SUB2 that are generalizations
of the add and sub instructions. ADD2 and SUB2 must allow the source
and destination to be almost anything. ADD2 must do the same thing
as an add instruction for all operands that are valid for add SUB2
must do the same thing as a sub instruction for all operands that are valid
for sub In addition, both macros must allow both source and destination
to be memory references and allow source and destination to be any register,
including DS, ES, and any of the A registers. Values that are bytes,
words, or double words must be added with ADD2 and subtracted with SUB2.
add3 result,
first, second
sub3
result, first, second
Macros named ADD3 and SUB3 that add (subtract)
the value in second to (from) the value in first and put the sum (difference)
in result. Neither first nor second should be changed by these macros.
result must be allowed to take almost any form (except an immediate
value); first and second are required to be memory references
Below is a listing of the current contents of mymacs.inc It contains three macros that are needed in p6temp.asm Change the name of mymacs.inc to yourname.inc; then add the other macros. Be sure to limit yourname to 8 characters or fewer. Also, change the fifth line of p6temp.asm to include yourname.inc
.nolist
;; Starter macros for the p6temp.asm program
;; Display a null terminated string that is stored in memory
;; Verifies that the operand is a memory reference;
uses
;; Irvine's library to display
showstring macro first
push dx
if ((opattr first) and 0002h) eq 0
echo Operand must be
a memory reference
.err
exitm
endif
mov dx, offset first
call Writestring
pop dx
endm
;; Display a double word unsigned integer that is held in the operand
;; Verifies that the operand is not already EAX,
then moves
;; the value there for Irvine's library routine
shownumber macro first
push eax
push bx
if (type first) ne 4
movsx eax, first
else
ifdif <first>,<eax>
mov eax, first
endif
endif
mov bx, 10
call Writelong
pop bx
pop eax
endm
;; Outputs a carriage return and line feed
;; Uses Irvine's library routine
newline macro
call crlf
endm
.list
Following is a listing of the program in p6temp.asm for your reference.
.model small
.386
.stack 100h
if1
include mymacs.inc ; Get the file with the macros
endif
.data
start db
"These are my results",0
highs dd
45, 50, 49, 56, 53, 60, 44, 34, 38, 50
lows dd
33, 30, 38, 40, 35, 44, 30, 29, 30, 31
diffs dd
10 dup(?)
highest dd ?
total dd
?
tlabel db
"Total differences ",0
hlabel db
"The highest temperature is ", 0
llabel db
"The lowest temperature is ", 0
dlabel db
"The differences are:",0
header db
100 dup(?)
.code
extern Writestring:proc, Writelong:proc, crlf:proc
main proc
gmov ds, @data
gmov cx, 10
gmov highest, highs
; Init highest
gmov eax, lows
; Init lowest
gmov total, 0
; Init difference total
gmov si, 0
; Init array position
top:
sub3 diffs[si], highs[si], lows[si]
; Get difference
add2 total, diffs[si]
; Add to total
gcmp highs[si], highest ;
Check for new high
jng skip
gmov highest, highs[si]
skip:
gcmp lows[si], eax
; Check for new low
jnl hop
gmov eax, lows[si]
hop:
add2 si, 4
; On to next entries
loop top
smov header, start
showstring header ; Display heading
newline
showstring tlabel ; Display total
differences
shownumber total
newline
showstring hlabel ; Display highest
temperature
shownumber highest
newline
showstring llabel ; Display lowest
temperature
shownumber eax
newline
showstring dlabel ; Display all
differences
newline
gmov cx, 10
gmov si, 0
round:
shownumber diffs[si] ; One difference per line
newline
add2 si, 4
loop round
gmov ax, 4c00h
int 21h
main endp
end main
You can find mymacs.inc and p6temp.asm in the world-read folder under your section of COSC300 on the P: drive. You can also find them in the jlwolfe\cosc300 folder on the I: drive. There is also another file in these two folders, p6bad.asm This is a file that deliberately uses the macros incorrectly; it is a test of the error checking features of your macros. When you attempt to assemble this file, it should produce a variety of macro-generated errors in the p6bad.lst file.
Hand in a printout of p6temp.lst
Be sure to print this in landscape form with 10-pt type. .LST
files that involve macros are often very wide. Hand in a printout
of the output generated by p6temp.exe Also, hand in a printout
of p6bad.lst; be sure it is in landscape form with 10-pt type.
Copy
yourname.inc to the hand-in folder under the appropriate section
for COSC300 on the P: dirve.