Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assembly Project

Status
Not open for further replies.

stevemei

Programmer
Mar 18, 2001
5
0
0
US
Hi, my name is Steve and i was wondering if i can get some help for my Assembly class project.

Project question:
1. Input 5 numbers between +5000 to -5000(if attempt to enter number outside this range an error message should be generated and the users must be allowed to try again. The program must tell the user the number(1 through 5) of the current entry(i.e. Input #1:, Input #2:, etc.)
. Display the 5 number sorted in ascending order and right hand justified
3. Display the sum of the five numbers

I am having problem writing the codes to sort them. so far what i have written outputs the sum and the five numbers input. Is there anyway i can sort them without using insertion sort?
Your response is greatly appreciated

INCLUDE PCMAC.INC

.MODEL SMALL

.STACK 100h

.DATA
Msg1 DB 'Enter(number bwt. 5000 and -5000) as input #', '$'
Msg2 DB 'Number out of range, enter a new one', 13, 10, '$'
Msg3 DB 'Sum of five inputs are ', '$'
N EQU 5
count DW 1
sum Dw 0
SaveSum DW ?

.CODE
EXTRN GetDec : NEAR, PutDec : NEAR

lab5 PROC
mov ax, @data
mov ds, ax

mov cx, N
jcxz laker2
loop1:
_PutStr Msg1 ; display Msg1

mov ax, count
call PutDec
inc count
_PutCh 13, 10


call GetDec

cmp ax, 5000 ; if (number <= 5000) and...
jnle laker1
cmp ax, -5000 ; (number >= -5000) then...
jnge laker1

jmp laker2
laker1:

_PutStr Msg2 ; display Msg2
call GetDec ; get number
laker2:
add ax, sum
mov sum, ax

loop loop1
mov ax, sum
mov SaveSum, ax
_PutStr Msg3
mov ax, SaveSum
call PutDec

_Exit 0

lab5 ENDP
END lab5





 
Insertion sort would be the easiest way, I think, what's the problem with that?

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
The problem is that i havent learned insertion sort yet. i was trying to figure out to sort with a loop but wasnt successful. I was using temp to compare each number input and it comes out with the Max. is there another way i can sort it without using insertion?

Thanks.
 
HI, may be u can try this.


First get i/p of all nums and store it in an array.
Have another array called &quot;destarray&quot; which will contain
the o/p.

1. Find the Smallest num from 1st array and enter into
second. Now make the smalles num in 1st array as infinity,
( in ur case 5001 would do ).

2. repeat the same for all numbers. Now, u have the sorted
form in &quot;destarray&quot;

Hope u got my point.

Are u the same &quot;shifty&quot; steve in IBAMP ?

Regards,
Sarnath
Do not rejoice that ur code works.
it might be a special case of an error :-(
 
How can I put an numbers 9,3,15,4,6,3,12,1,0,8 in ascending order using assembly language. What codes should I used. CMP, JNE, LOOP. I been working on this project for 3 weeks it drives me cracy. I have everything else but the main program. I have no idea how to do this. PLEASE some one help me....
 
How can I put an numbers 9,3,15,4,6,3,12,1,0,8 in ascending order using assembly language. What codes should I used. CMP, JNE, LOOP. I been working on this project for 3 weeks it drives me cracy. I have everything else but the main program. I have no idea how to do this. PLEASE some one help me....
 
Kasia,
if u r that confused, first try finding out
smallest and largest of the given numbers, that
will lubricate ur friction with assemly.
If u do this, u'll do sorting automatically.
See the 2nd response here. it has details about sorting.

Hope it helps u.
cheers,
sarnath
Do not rejoice that ur code works.
it might be a special case of an error :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top