Having trouble with a homework question for NASM using ALong32. You are to read
ID: 3735598 • Letter: H
Question
Having trouble with a homework question for NASM using ALong32.
You are to read in N integers, terminated by a value of zero, which will not be used. You are to sort these numbers into ascending order and print them out. You must produce an error message if either no data is entered prior to a value of zero, or if too much data is entered and would overflow your array. You should plan on handling at least 100 integer values to properly size your array.
Here is what I have so far:
%include "ALong32.inc"
global main
section .data
MYARRAY TIMES 100 DW 0;1 ROW * 100 COLUMNS
counter dq 0 ;counter
firstInt dq 0 ;input number that will be added to intTotal
four dq 0; 4 int constant
result dq 0
input1 dd "Input integer: ",0
noData dd "No data entered",0
tooMuch dd "Too much data",0
section .text
_start:
mov word [four], 4; four=4
mov edx, input1 ;input1=edx
call WriteString
call ReadInt
mov [firstInt], eax ;firstInt=eax
cmp eax, 0 ;is eax = 0?
jz exit ;if so, exit program
cmp edx, 0x00
je none
jmp continue
none:
mov edx, noData
call WriteString
call Crlf
continue:
mov [firstInt], edx
imul ecx,ebx,four
mov [result],ecx
;add to array
inc ebx
cmp ebx, 100
je exit
mov [counter],ebx
jmp continue
exit:
mov eax, 01h ; exitC)
mov ebx, 0h ; errno
int 80h
Explanation / Answer
Read a byte from stdin
mov eax,3
push dword 1
push dword variable
push dword 0
push eax
int 0x80
add esp,16
To read in a single character from standard input
mov eax,3
mov ebx,0
mov ecx,variable
mov edx,1
int 0x80
print a byte to stdout
mov eax,4
mov ebx,1
mov ecx,variable
mov edx,1
int 0x80
sort numbers into ascending order
push ecx;
desc ecx
push ecx;
loop L3
pop ecx;
setWrite:
xor ebx,ebx
pop ecx;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.