Author Topic: maximum of 5 number in two decimal masm 16 bit  (Read 1844 times)

samirsoft

  • Regular Member
  • *
  • Posts: 4
maximum of 5 number in two decimal masm 16 bit
« on: December 31, 2017, 09:25:40 AM »
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

  • Member
  • *****
  • Posts: 8731
  • Assembler is fun ;-)
    • MasmBasic
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #1 on: December 31, 2017, 10:22:21 AM »
Post your complete code, perhaps we can help you then.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5758
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #2 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

felipe

  • Member
  • ****
  • Posts: 927
  • Eagles are just great!
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #3 on: December 31, 2017, 01:07:31 PM »
wish are in two decimal " _ _ "

Do you mean numbers of 2 digits?
Felipe.

samirsoft

  • Regular Member
  • *
  • Posts: 4
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #4 on: December 31, 2017, 09:57:45 PM »
wish are in two decimal " _ _ "

Do you mean numbers of 2 digits?
yes ,  "01"....... "99"

samirsoft

  • Regular Member
  • *
  • Posts: 4
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #5 on: December 31, 2017, 09:58:46 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

AW

  • Member
  • *****
  • Posts: 1477
  • Let's Make ASM Great Again!
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #6 on: December 31, 2017, 10:07:41 PM »
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
« Last Edit: January 01, 2018, 05:02:09 AM by aw27 »

samirsoft

  • Regular Member
  • *
  • Posts: 4
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #7 on: January 01, 2018, 04:55:57 AM »
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

AW

  • Member
  • *****
  • Posts: 1477
  • Let's Make ASM Great Again!
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #8 on: January 02, 2018, 03:33:18 AM »
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.  :(

AW

  • Member
  • *****
  • Posts: 1477
  • Let's Make ASM Great Again!
Re: maximum of 5 number in two decimal masm 16 bit
« Reply #9 on: January 02, 2018, 05:14:31 PM »
Here is the code, but be aware that your teacher may come here :P:

Code: [Select]
;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