News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

maximum of 5 number in two decimal masm 16 bit

Started by samirsoft, December 31, 2017, 09:25:40 AM

Previous topic - Next topic

samirsoft

hi
i need help for masm 16bit to find the maximum of 5 number enter by the user wish are in two decimal " _ _ "
thank you so much

jj2007

Post your complete code, perhaps we can help you then.

hutch--

samir,

Do not double post in this forum. I moved your question to the 16 bit forum so you had a better chance of getting an answer.

felipe



samirsoft

Quote from: hutch-- on December 31, 2017, 12:44:16 PM
samir,

Do not double post in this forum. I moved your question to the 16 bit forum so you had a better chance of getting an answer.
thank you

aw27

#6
How do you enter the 5 numbers? This is the most important part because finding the largest one is too easy to mention.

This looks like a school assignment and the numbers are to be entered using the Irvine library.  :P

samirsoft

Quote from: aw27 on December 31, 2017, 10:07:41 PM
How do you enter the 5 numbers? This is the most import part because finding the largest one is too easy to mention.

This looks like a school assignment and the numbers are to be entered using the Irvine library.  :P
it is school assignment , user enter 5 nomber ( in array maybe ) and the programme find the max of the nombers

aw27

Quote from: samirsoft on January 01, 2018, 04:55:57 AM
Quote from: aw27 on December 31, 2017, 10:07:41 PM
How do you enter the 5 numbers? This is the most import part because finding the largest one is too easy to mention.

This looks like a school assignment and the numbers are to be entered using the Irvine library.  :P
it is school assignment , user enter 5 nomber ( in array maybe ) and the programme find the max of the nombers
This can't be "may be", it is the most important part.
Once you have the five numbers it is uncomplicated to sort them.

You can do a Bubble Sort, for instance. Just in case you don't know what was that, I searched the wikipedia for you:

"The algorithm starts at the beginning of the data set. It compares the first two elements, and if the first is greater than the second, it swaps them. It continues doing this for each pair of adjacent elements to the end of the data set. It then starts again with the first two elements, repeating until no swaps have occurred on the last pass. This algorithm's average time and worst-case performance is O(n2), so it is rarely used to sort large, unordered data sets. Bubble sort can be used to sort a small number of items (where its asymptotic inefficiency is not a high penalty). "

PS: I read again what you want, the maximum, so you don't even need to sort the array.

Of course, if you don't have the slightest idea of the x86 instruction set it might be a nightmare. You have my sympathy if this is the case.  :(

aw27

Here is the code, but be aware that your teacher may come here :P:


;ml /c test.asm
;link16 /tiny test.obj

.186

code  segment
      assume  cs:code,ds:code
      org     100h
begin:
      jmp     start
inArray db 5 dup(0);
enterMsg db "Enter 5 Numbers between 00 and 99.",13,10,"$"
enterNumb db 13,10,"Enter Number: $"
sayMaximum db 13,10, "Maximum number is: $"
errmsg db 13,10,"Invalid input$"
numCount dw 5
maxNum db ?

start:
mov dx,offset enterMsg
mov ah,09h
int 21h

inpStart:
cmp numCount,0
jz inputEnd
mov dx,offset enterNumb
mov ah,09h
int 21h
dec word ptr numCount
call getNumber
jc error1
mov si, offset inArray
add si, numCount
mov byte ptr [si], al
jmp inpStart

inputEnd:
mov cx, 0
mov al, 0
mov si, offset inArray
dec si
looper:
inc si
cmp cx, 5
jae looperExit
add cx,1
cmp al, byte ptr [si]
ja looper
mov al, byte ptr [si]
jmp looper

looperExit:
mov maxNum, al
mov dx, offset sayMaximum
mov ah,09h 
int 21h
xor ax, ax
mov al, maxNum
mov dx, 10
div dl
push ax
mov dl, al
add dl, 30h
mov ah, 2
int 21h
pop ax
mov dl, ah
add dl, 30h
mov ah, 2
int 21h

mov ah, 4ch
int 21h
error1:
mov dx,offset errmsg
mov ah,09h
int 21h
mov ah, 4ch
int 21h


getNumber  proc near ; Accepts only 00 to 99
sub bh,bh
mov dl,10

mov ah,1
int 21h
cmp al,"0"                 
jb g_error               
cmp al,"9"
ja g_error
sub al, 30h
mul dl                     
jc g_error               
cmp al, 100
ja g_error
mov bh, al
mov ah,1
int 21h
cmp al,"0"                 
jb g_error               
cmp al,"9"
ja g_error
sub al, 30h
add al, bh
clc
ret
g_error:     
stc
ret
getNumber  endp

code  ends

end  begin



Enter 5 Numbers between 00 and 99.

Enter Number: 21
Enter Number: 66
Enter Number: 43
Enter Number: 61
Enter Number: 09
Maximum number is: 66