Question: This is MASM x 8 6 Assembly. Even with the code that was provided in my previous follow - up question this is the output

This is MASM x86 Assembly. Even with the code that was provided in my previous follow-up question this is the output I am receiving. This is in Visual Studio 2022. my code: INCLUDE Irvine32.inc
.386
.stack 4096
; macros
mGet MACRO promptAddr, bufferAddr, bufferSize
lea edx, promptAddr
call WriteString ; Display the prompt
mov edx, bufferAddr
mov ecx, bufferSize
call ReadString ; Get user input
ENDM
mDisplayString MACRO stringAddr
mov edx, stringAddr
call WriteString ; Display a string
ENDM
mDisplayChar MACRO charValue
mov al, charValue
call WriteChar ; Display a character
ENDM
; constants
TEMPS_PER_DAY EQU 24 ; Expected number of temperatures
DELIMITER EQU ',' ; Delimiter for temperatures
BUFFER EQU 128 ; Buffer size
.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:\\temp\\Temps090124.txt",0
fileBuffer BYTE BUFFER DUP(?) ; Buffer to hold file contents
arrayTemps SDWORD TEMPS_PER_DAY DUP(?) ; Array for temperatures
.code
main PROC
; Prompt for file name
mGet getFileName, OFFSET tempFileName, BUFFER
; Open the file
mov edx, OFFSET tempFileName
call OpenInputFile
JC FileError ; Jump to error handler if file not found
; Read file contents
mov edx, OFFSET fileBuffer
mov ecx, BUFFER
call ReadFromFile
cmp eax, 0
je FileError ; Handle empty file
cmp eax, BUFFER
jae FileError ; Handle buffer overflow
; Parse and store temperatures
PUSH OFFSET fileBuffer
PUSH OFFSET arrayTemps
call ParseTempsFromString
; Display the parsed temperatures in reverse order
mDisplayString OFFSET outputMsg
PUSH OFFSET arrayTemps
call WriteReverse
; Exit program
jmp EndProg
FileError:
; Handle file errors
mov edx, OFFSET giveError
call WriteString
jmp EndProg
EndProg:
invoke ExitProcess, 0
main ENDP
; Parse temperatures from the string
ParseTempsFromString PROC
push ebp
mov ebp, esp
mov esi, [ebp+8] ; Source buffer address
mov edi, [ebp+12] ; Destination array address
xor ebx, ebx ; Accumulate integer values
xor edx, edx ; Sign flag (0 for positive, 1 for negative)
ParseLoop:
lodsb ; Load next byte from source buffer
test al, al ; Check for null terminator
jz StoreLastValue
cmp al, DELIMITER ; Check for delimiter
je StoreValue
cmp al,'-' ; Check for negative sign
je NegativeNum
cmp al,'0' ; Check for valid numeric range
jb SkipChar
cmp al,'9'
ja SkipChar
sub al,'0' ; Convert ASCII to numeric
imul ebx, 10 ; Accumulate into integer
add ebx, eax
jmp ParseLoop
NegativeNum:
inc edx ; Set sign flag for negative number
jmp ParseLoop
StoreValue:
test edx, edx
jz PositiveNum
neg ebx ; Convert to negative if sign flag is set
PositiveNum:
mov [edi], ebx ; Store integer into destination array
add edi, 4 ; Move to next position in array
xor ebx, ebx ; Reset accumulator
xor edx, edx ; Reset sign flag
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
; Write the array in reverse order
WriteReverse PROC
push ebp
mov ebp, esp
mov esi, [ebp+8] ; Array address
mov ecx, TEMPS_PER_DAY ; Number of elements
lea esi, [esi + ecx*4] ; Move to end of array
WriteLoop:
sub esi, 4 ; Move to previous element
mov eax, [esi] ; Load element into EAX
call WriteInt ; Display the integer
call Crlf ; Print newline
loop WriteLoop
pop ebp
ret
WriteReverse ENDP
END main
This is MASM x 8 6 Assembly. Even with the code

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!