Question: Here's the updated code with the recommendations: INCLUDE Irvine 3 2 . inc . 3 8 6 . stack 4 0 9 6 ; macros

Here's the updated code with the recommendations: INCLUDE Irvine32.inc
.386
.stack 4096
; 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
TEMPS_PER_DAY EQU 24
DELIMITER EQU ','
BUFFER EQU 128
.data
getFileName BYTE "Enter file name: ",0
giveError BYTE "Error occurred trying to open this file. ",0
outputMsg BYTE "The temperatures in the correct order: ",0
tempFileName BYTE "C:\\Users\\Desktop\\Assignment 6\\Project0\\Temps090124.txt",0
fileBuffer BYTE BUFFER DUP(?)
arrayTemps SDWORD TEMPS_PER_DAY DUP(?)
numTemps SDWORD 0
.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, 0
jle FileError
mov byte ptr [edx +eax],0
; 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,0
main ENDP
ParseTempsFromString PROC
push ebp
mov ebp, esp
mov esi, [ebp +8]
mov edi, [ebp +12]
xor ebx, ebx
xor edx, edx
ParseLoop:
lodsb
test al,al
jz StoreLastValue
cmp al,DELIMITER
je StoreValue
cmp al,'-'
je NegativeNum
cmp al,'0'
jb SkipChar
cmp al,'9'
ja SkipChar
; Convert ASCII to integer (0-9)and add to running total
sub al,'0'
imul ebx, 10
add ebx, eax
jmp ParseLoop
NegativeNum:
inc edx
jmp ParseLoop
StoreValue:
; If a number was accumulated, store it in arrayTemps
cmp ebx, 0
je ClearFlags
test edx, edx
jz PositiveNum
neg ebx
PositiveNum:
mov [edi],ebx
add edi, 4
call WriteInt
inc numTemps
xor ebx, ebx
xor edx, edx
ClearFlags:
jmp ParseLoop
SkipChar:
jmp ParseLoop
StoreLastValue:
; Handle last value if one exists
cmp ebx, 0
je ExitParseLoop
test edx, edx
jz PositiveLast
neg ebx
PositiveLast:
mov [edi],ebx ; store the last number
add edi, 4
call WriteInt
inc numTemps ; count the last value as well
ExitParseLoop:
pop ebp
ret
ParseTempsFromString ENDP
WriteReverse PROC
push ebp
mov ebp, esp
mov esi, [ebp +8]
mov ecx, numTemps
test ecx, ecx
je ExitWriteReverse
lea esi, [esi +ecx *4]
WriteLoop:
sub esi, 4
mov eax, [esi]
call WriteInt
loop WriteLoop
ExitWriteReverse:
pop ebp
ret
WriteReverse ENDP
END main the console output im getting from this: Enter file name: Temps090124.txt
-3,-2,0,3,7,10,15,20,25,30,35,40,45,42,38,34,30,25,20,15,10,5,2,-1,The temperatures in the correct order: (it ends here with no corrected version)and this is Temps090124.txt: -3,-2,0,3,7,10,15,20,25,30,35,40,45,42,38,34,30,25,20,15,10,5,2,-1,the output i need is: Enter the name of the file to be read: Temps090124.txt Here's the corrected temperature order! -1,+2,+5,+10,+15,+20,+25,+30,+34,+38,+42,+45,+40,+35,+30,+25,+20,+15,+10,+7,+3,+0,-2,-3, can you write the updated version of this file, that actually works this time.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!