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 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\\Gwen\\Desktop\\CS271\\Assignment 6\\Project0\\Temps090124.txt",0
fileBuffer BYTE BUFFER DUP(?)
arrayTemps SDWORD TEMPS_PER_DAY 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, 0
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,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
sub al,'0'
imul ebx, 10
add ebx, eax
jmp ParseLoop
NegativeNum:
inc edx
jmp ParseLoop
StoreValue:
test edx, edx
jz PositiveNum
neg ebx
PositiveNum:
mov [edi], ebx
add edi, 4
xor ebx, ebx
xor edx, edx
jmp ParseLoop
SkipChar:
jmp ParseLoop
StoreLastValue:
cmp ebx, 0
je ExitParseLoop
test edx, edx
jz PositiveLast
neg ebx
PositiveLast:
mov [edi], ebx
add edi, 4
ExitParseLoop:
pop ebp
ret
ParseTempsFromString ENDP
WriteReverse PROC
push ebp
mov ebp, esp
mov esi, [ebp+8]
mov ecx, TEMPS_PER_DAY
lea esi, [esi + ecx *4]
WriteLoop:
sub esi, 4
mov eax, [esi]
call WriteInt
loop WriteLoop
pop ebp
ret
WriteReverse ENDP
END main
this is the output it gives me :
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: +0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0

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!