Question: This is my code right now with the updates that you suggested: INCLUDE Irvine 3 2 . inc . 3 8 6 . stack 4
This is my code right now with the updates that you suggested:
INCLUDE Irvineinc
stack
; macros
mGet MACRO promptAddr, bufferAddr, bufferSize
lea edx, promptAddr
call WriteString
mov edx, bufferAddr
mov ecx, bufferSize
call ReadString
ENDM
mDisplayString MACRO stringAddr
mov edx, stringAddr
call WriteString
ENDM
mDisplayChar MACRO charValue
mov al charValue
call WriteChar
ENDM
; constants
TEMPSPERDAY EQU
DELIMITER EQU
BUFFER EQU
data
getFileName BYTE "Enter file name:
giveError BYTE "Error occurred trying to open this file.
outputMsg BYTE "The temperatures in the correct order:
tempFileName BYTE C:UsersGwenDesktopCSAssignment ProjectTempstxt
fileBuffer BYTE BUFFER DUP
arrayTemps SDWORD TEMPSPERDAY DUP
code
main PROC
; get file name
mGet getFileName, OFFSET tempFileName, BUFFER
; open file
mov edx, OFFSET tempFileName
call OpenInputFile
JC FileError
; read file
mov edx, OFFSET fileBuffer
mov ecx, BUFFER
call ReadFromFile
cmp eax,
je FileError
cmp eax, BUFFER
jae FileError
; display file
mov edx, OFFSET fileBuffer
call WriteString
; put temps in right order
PUSH OFFSET fileBuffer
PUSH OFFSET arrayTemps
call ParseTempsFromString
; display new order
mDisplayString OFFSET outputMsg
PUSH OFFSET arrayTemps
call WriteReverse
; exit
jmp endProg
FileError:
mov edx, OFFSET giveError
call WriteString
jmp EndProg
EndProg:
Invoke ExitProcess,
main ENDP
ParseTempsFromString PROC
push ebp
mov ebp, esp
mov esi, ebp
mov edi, ebp
xor ebx, ebx
xor edx, edx
ParseLoop:
lodsb
test al al
jz StoreLastValue
cmp al DELIMITER
je StoreValue
cmp al
je NegativeNum
cmp al
jb SkipChar
cmp al
ja SkipChar
sub al
imul ebx,
add ebx, eax
jmp ParseLoop
NegativeNum:
inc edx
jmp ParseLoop
StoreValue:
test edx, edx
jz PositiveNum
neg ebx
PositiveNum:
mov edi ebx
add edi,
xor ebx, ebx
xor edx, edx
jmp ParseLoop
SkipChar:
jmp ParseLoop
StoreLastValue:
cmp ebx,
je ExitParseLoop
test edx, edx
jz PositiveLast
neg ebx
PositiveLast:
mov edi ebx
add edi,
ExitParseLoop:
pop ebp
ret
ParseTempsFromString ENDP
WriteReverse PROC
push ebp
mov ebp, esp
mov esi, ebp
mov ecx, TEMPSPERDAY
lea esi, esi ecx
WriteLoop:
sub esi,
mov eax, esi
call WriteInt
loop WriteLoop
pop ebp
ret
WriteReverse ENDP
END main
this is the output it gives me :
Enter file name: Tempstxt
The temperatures in the correct order:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
