The instructor told us if we put our matrix into memory, it would limit the matrix size but he did not say we would be penalized for it. He also gave the class an extension until Thursday afternoon to get the code running. Only thing left for me to get working is the command tail and then I need to start checking that everything is working:
.MODEL SMALL ;Defines memory model as small which uses seperate segments for code and data
.386 ;Microprocessor number
.STACK ;Stack segment defined as 1024 by default
.DATA ;Begins definition of the data type used in this project
mrc DD ?
scale DD ?
D DD ?
row DB ?
col DB ?
e DD ?
ep1 DD ?
M DD 10000 DUP(?)
INPUT DB "input", 0
OUTPUT DB "output", 0
;-------------------------------------------------------------------------------------
;calcoffset takes two input variables and calculates the equation: (op2-1)*op1+(op1-1)
;The value is returned into M[EAX]
;-------------------------------------------------------------------------------------
calcoffset MACRO op1, op2
PUSH ESI
PUSH EDI
MOV ESI, op1
MOV EDI, op2
DEC EDI
MUL EDI
ADD EAX, ESI
DEC EAX ;M[EAX]
POP EDI
POP ESI
ENDM
;------------------------------------------------------------------------------------
.CODE
MAIN PROC FAR
.STARTUP
;Program:
PUSHAD
MOV EAX, 0h
MOV AH, 62h
INT 21H
MOV ES, BX
MOV SI, 81h
CMP BYTE PTR ES: [SI-1], 1
JBE NO_TAIL
NO_TAIL: MOV DL, 0Ah
INT 21H
MOV DL, 0Dh
INT 21H
MOV BP, 0
MOV SI, 0
MOV AX, 3D02h ;Open file
MOV DX, OFFSET INPUT
INT 21H
MOV BX, AX
MOV CX,2 ;Want to read two bytes.
MOV DX, OFFSET D
MOV AH, 3FH ;Read
INT 21H
JC QUIT
CMP AX,2
JNE QUIT
MOV CX,8 ;Want to read eight bytes.
MOV DX, OFFSET M
MOV AH, 3FH ;Read
INT 21H
JC QUIT
CMP AX, 8
JNE QUIT
MOV ESI, 1
MOV EDI, 1
MOVZX EAX, row
MOV ECX, ESI
MOV EBP, 1
DEC ECX
L1:
calcoffset EBP, EBP
MOV EDX, M[EAX]
MOV e, EDX
INC ESI
MOV ESI, EBP
MOV EDI, EBP
calcoffset ESI, EBP
MOV EDX, M[EAX]
MOV ep1, EDX
;calc scale to fpu
FINIT
FLD e
FLD ep1
FDIV
FST scale
JMP L2
RETURN: JMP L1
L2:
calcoffset ESI, EDI
MOV EDX, M[EAX]
MOV mrc, EDX
;fpu to calc mrc*scale+e
FINIT
FLD mrc
FLD scale
FMUL
FCHS
FLD e
FADD
FST mrc
INC EDI
MOVZX EDX, col
CMP EDI, EDX
JBE L2
INC ESI
MOVZX EDX, row
CMP ESI, EDX
JBE L2
JMP RETURN
MOV AX, 3D02h
MOV DX, OFFSET OUTPUT
INT 21H
MOV BX, AX
MOV CX, LENGTHOF M
MOV DX, LENGTHOF M
MOV AH, 40h
INT 21H
MOV AH, 3Eh
INT 21H
QUIT: .EXIT
MAIN ENDP
END