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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Largest Number

Status
Not open for further replies.

MFLO

Programmer
Nov 24, 2002
4
US
I'm still in the process of learning assembly language, so i would greatly appreciate any and all help i can get.

how do i find the largest number out of five numbers in an array when the numbers are in Hex and how do i display the largest number once i find it?

Thanks for any and all help!
 
It's MFLO again.

this is what i have sofar:

.MODEL SMALL
.STACK 64
;--------------------------
.DATA
COUNT EQU 05
DATA DB 1,2,3,4,5
ORG 0008H
LARGEST DW ?
;--------------------------
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV CX,COUNT ;CX is the loop counter
MOV SI,OFFSET DATA
MOV AX,00
BACK:

;I'm not sure what goes here

JNZ BACK ;If not finished, go to BACK
MOV AH,4CH
INT 21H ;Go back to DOS
MAIN ENDP
END MAIN

i is there anything wrong with my setup? and i still have no idea what do during the loop to find the greatest value of the 5 values entered earlier
 
Hi..

I don't have a nice assembler here at work but I got debug, so I'll post some debug-code..

But first... think about how you would do that task.. normally one would use a 2 step algorithm:

[A0] n=1; x <- [n]
[A1] see if the next number is bigger... if it is take it and discard the old number..
n <- n+1
if x<[n] : x <- [n]
[A2] repeat [A1] for each number [n]

and with some extra stuff around I got this:
(just copy&paste into a debug prompt)
---------
a 100
xor bp, bp
mov cx, [199]
mov ah, 9
mov dx, 162
int 21
mov ah,02
mov dx, [19B+bp]
add dx, 30
int 21
mov dl,20
int 21
add bp, 2
loop 10F
mov dl,a
int 21
mov dl,d
int 21
xor bp, bp
xor ax, ax
mov cx, [199]
mov dx, [19B+bp]
cmp ax, dx
jc 140
add bp, 2
loop 131
jmp 147
mov ax, dx
add bp, 2
loop 131
push ax
mov ax, 900
mov dx, 181
int 21
mov ah,02
pop dx
add dx, 30
int 21
mov dl,a
int 21
mov dl,d
int 21
int 20

e 162 &quot;I will compare these numbers: $&quot;
e 181 a,d,&quot;This is the largest: $&quot;

a 199
dw 5
dw 1,3,2,5,4


rcx
1A5

n largest.com
w
q
--------

You'll notice that the output will only work for numbers 0-9 any bigger and the simple +30 will result in strange output...
also, if you wanna change the amount of numbers (the first dw) and the numbers itself.. don't forget to add to the cx value (rcx)

you can trace through the program with t on the debug prompt...
 
It's easier if you convert the hex string into a binary number first. &quot;Information has a tendency to be free. Which means someone will always tell you something you don't want to know.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top