Hi all,

i need an assembly 8086 code that compare between numbers from 1 to 99 and write output messege contain > or < or =

can any body help me

I HAVE A PROBLE, HELP ME PLEASE

.MODEL SMALL
.STACK 64 
.DATA
   MS1 DB 23 DUP('ENTER THE FIRST DIGIT: ')
   MS2 DB 23 DUP('ENTER THE SECOND DIGIT: ')
   MSG1 DB 23 DUP('FIRST DIGIT > SECOND DIGIT')
   MSG2 DB 23 DUP('FIRST DIGIT < SECOND DIGIT')
   MSG3 DB 23 DUP('FIRST DIGIT = SECOND DIGIT')
   NUM1 DB ?
   NUM2 DB ?
   DEC1 DB 10
   ONE DB '1'
   
   E DB 0AH,0DH
   SUM1 DB ?
   SUM2 DB ?
   LEN1 DW ?
   LEN2 DW ?


.CODE
   MOV AX,@DATA
   MOV DS,AX

;FIRST DIGIT
   CALL READ
   MOV CX,23
   LEA DX,MS1
   INT 21H

   CALL WRITE
   MOV CX,7
   LEA DX,NUM1[SI]
   INT 21H 
   
   SUB AX,2
   MOV LEN1,AX
  
   MOV CX,LEN1
   MOV SI,0
   XOR BX,BX

L1:
   AND NUM1[SI],0FH
   SHR NUM1[SI],1
   RCL BL,1
   INC SI
LOOP L1
   
   MOV SUM1,BL  
   CMP SUM1,9
   JG NEXT
   ADD SUM1,30H
   JMP COMPARE

   ;CALL READ
   ;MOV CX,1
   ;LEA DX,SUM1
   ;INT 21H

  
NEXT:
   XOR AX,AX
   MOV AL,SUM1
   DIV DEC1
   MOV SUM1,AH
   ADD SUM1,30H
   JMP COMPARE

   ;CALL READ
   ;MOV CX,1
   ;LEA DX,ONE
   ;INT 21H
   
   ;CALL READ
   ;MOV CX,1
   ;LEA DX,SUM1
   ;INT 21H
   

;///////////////////////////////////
;SECOND DIGIT
   CALL READ
   MOV CX,23
   LEA DX,MS2
   INT 21H

   CALL WRITE
   MOV CX,7
   LEA DX,NUM2[SI]
   INT 21H 
   
   SUB AX,2
   MOV LEN2,AX
  
   MOV CX,LEN2
   MOV SI,0
   XOR BX,BX

L2:
   AND NUM2[SI],0FH
   SHR NUM2[SI],1
   RCL BL,1
   INC SI
LOOP L2
   
   MOV SUM2,BL  
   CMP SUM2,9
   JG NEXT1
   ADD SUM2,30H
   JMP COMPARE

   ;CALL READ
   ;MOV CX,1
   ;LEA DX,SUM2
   ;INT 21H

   JMP FINISH

NEXT1:
   XOR AX,AX
   MOV AL,SUM2
   DIV DEC1
   MOV SUM2,AH
   ADD SUM2,30H
   JMP COMPARE

   ;CALL READ
   ;MOV CX,1
   ;LEA DX,ONE
   ;INT 21H
   
   ;CALL READ
   ;MOV CX,1
   ;LEA DX,SUM2
   ;INT 21H

FINISH:
   MOV AX,4C00H
   INT 21H 
  
;///////////////////////////////////   
READ PROC NEAR

   MOV AH,40H
   MOV BX,01H

RET
READ ENDP
  
;///////////////////////////////////   
write PROC NEAR
   
   MOV AH,3FH
   MOV BX,00H
   
RET
WRITE ENDP
;///////////////////////////////////   
COMPARE PROC NEAR
  
   XOR AX,AX
   XOR BX,BX
   MOV AL,SUM1
   MOV BL,SUM2

   CMP AX,BX
   JG GREATER
   JL LESS
   CALL READ
   MOV CX,23
   LEA DX,MSG3
   INT 21H
   

GREATER:
   CALL READ
   MOV CX,23
   LEA DX,MSG1
   INT 21H

LESS:
CALL READ
   MOV CX,23
   LEA DX,MSG2
   INT 21H
RET
COMPARE ENDP

;///////////////////////////////////
END

Hey Sara, I don't mean to be too harsh, but at your current level this is waaay over your head.

It appears that you have been hacking at the above code for some time because it is a mess. If this is a school assignment it might be a good idea to drop the assembly class and concentrate on the C/C++/Java classes first. If this is just on your own then save assembly for some time after you become comfortable with C/C++/etc...

I can help you, but you must know that assembly requires a great deal more concentration and organization of your thoughts than typically required to pass courses in high-level languages (like C/etc.), and I have no intention of just giving you answers so you'll have to work for it.

Let me know what you want to do.

thanks, but i need an assembly code,
can you help
ineed a program to compare numbers between 1 amd 99, can you tell me how,

aslo, can you help me in java,

I'm sorry, but like I said, I will not give you code. I will help you with the code you have. There is a distinct difference.

What you have above is likely to hurt you more than help, so I would start over if I were you. First, write what you want to do in a very simple C program or pseudo code. Something like the following is a good start:

char number1string[20], number2string[20];
int number1, number2;

printf( "Please enter the first number: " );
fgets( number1, 20, stdin );
number1 = convert_to_int( number1string );

/* and so on */

Once you have a good high-level idea of what you want to do it is easy to translate things to a low-level representation. Each of the above lines easily convert into a maximum of about 4 lines of their equivalents in assembly.

Here is a very handy INT 21h table.

Looking at that table I see that function 09h writes a string to the standard output. The string must be terminated with a '$' character. So:

.data
ask_for_first_number db 'Please enter the first number: $'

.code
; required initializations
mov ax, @data
mov ds, ax

; printf( "Please enter the first number: " );
mov ah, 09h
lea dx, ask_for_first_number
int 21h

; etc...

Do this and post again when you get stuck.

thanks, but i wrote a program, but it deals with all number and i need it to deal with numbers from 1 to 99 only.

here is my code.

///////////////////////////
.MODEL SMALL
.STACK 64 
.DATA
   MS1 DB 23 DUP('ENTER THE FIRST DIGIT: ')
   MS2 DB 23 DUP('ENTER THE SECOND DIGIT: ')
   MSG1 DB 26 DUP('FIRST DIGIT > SECOND DIGIT')
   MSG2 DB 26 DUP('FIRST DIGIT < SECOND DIGIT')
   MSG3 DB 26 DUP('FIRST DIGIT = SECOND DIGIT')
   NUM1 DB ?
   NUM2 DB ?
   TEN DB 10
   E DB 0AH,0DH
   LEN1 DW ?
   LEN2 DW ?


.CODE
   MOV AX,@DATA
   MOV DS,AX

  CALL FIRST_DIGIT
  CALL SECOND_DIGIT

   XOR AX,AX
   XOR BX,BX
   MOV AL,NUM1
   MOV BL,NUM2
   CALL COMPARE
   JMP FINISH
;///////////////////////////////////
COMPARE PROC

   CMP AL,NUM2
   JG GREATER
   
   CMP AL,NUM2
   JL LESS
   CALL READ
   MOV CX,26
   LEA DX,MSG3
   INT 21H
   JMP FINISH
   

   GREATER:
   CALL READ
   MOV CX,26
   LEA DX,MSG1
   INT 21H
   JMP FINISH

   LESS:
   CALL READ
   MOV CX,26
   LEA DX,MSG2
   INT 21H
RET
COMPARE ENDP

FINISH:
   MOV AX,4C00H
   INT 21H 

;///////////////////////////////////
FIRST_DIGIT PROC

   CALL READ
   MOV CX,23
   LEA DX,MS1
   INT 21H

   CALL WRITE
   MOV CX,7
   LEA DX,NUM1
   INT 21H
   
   SUB AX,2
   MOV LEN1,AX
  
   MOV CX,LEN1
   MOV SI,0
   XOR BX,BX

   CMP NUM1,9
   JG NEXT
   MOV AL,NUM1
   SUB AL,30H
   
NEXT:
   XOR AX,AX
   MOV AL,NUM1
   SUB AL,30H
   MOV BL,TEN
   MUL BL
   SUB AL,30H
   
RET
FIRST_DIGIT ENDP   

;///////////////////////////////////
SECOND_DIGIT PROC

   CALL READ
   MOV CX,23
   LEA DX,MS2
   INT 21H

   CALL WRITE
   MOV CX,7
   LEA DX,NUM2
   INT 21H 
   
   SUB AX,2
   MOV LEN2,AX
  
   MOV CX,LEN2
   MOV SI,0
   XOR BX,BX
   
   CMP NUM2,9
   JG NEXT1
   MOV AL,NUM2
   SUB AL,30H

NEXT1:
   XOR AX,AX
   MOV AL,NUM2
   SUB AL,30H
   MOV BL,TEN
   MUL BL
   SUB AL,30H
 
RET
SECOND_DIGIT ENDP
;///////////////////////////////////   
READ PROC NEAR

   MOV AH,40H
   MOV BX,01H

RET
READ ENDP
  
;///////////////////////////////////   
write PROC NEAR
   
   MOV AH,3FH
   MOV BX,00H
   
RET
WRITE ENDP
;///////////////////////////////////   

END

Just check to see that the number is not less than one or greater than 99.

Can You Tell Me How, I Check But I Jave Many Error

Yes, your code is littered with errors, which is why I advised you to toss it and start anew. The fact that it works is a trick on you.

If you wrote any of the stuff above then you should know how to compare a number in a register to see if it is larger or smaller than another number.

the last code i post is work correctly and this method i must use, ok

how to check numbers, please i must poet it tommorow,

sorry to interrupt
but i dont understand what the FIRST DIGIT & SECOND DIGIT procedures are doing here...what are u trying to do by calling them in very first few lines of your program.

well if you are having assembly course in your college then i will suggest you to write these few subroutines which will help you to program throughout your course...

make a standard subroutine for
1. inputting an integer
2. outputting an integer
3. printing a string

then you can solve this problem by calling INPUT_INT procedure twice... save them in two varaibles

compare them using CMP instruction...

and output accordingly a string already declared....

.model small
.stack 64
.data
msg1 db "please enter a number: ", 10, 13, '$'
msg2 db "please enter another number: ", 10, 13, '$'
equalMsg db "both numbers are equal", 10, 13, '$'
newline db 13,10,'$'

num1 label byte
max1 db 20
len1 db ?
s1 db 20 dup(?)

num2 label byte
max2 db 20
len2 db ?
s2 db 20 dup(?)

.code
begin proc

mov ax, @data
mov ds, ax
mov es, ax

mov ah, 09h
mov dx, offset msg1
int 21h

mov dx, offset max1
mov ah, 0ah
int 21h

mov dx, offset newline
mov ah, 9h
int 21h

mov bx, 0h
mov bl, len1
mov s1[bx], '$'

mov ah, 09h
mov dx, offset msg2
int 21h

mov dx, offset max2
mov ah, 0ah
int 21h

mov dx, offset newline
mov ah, 9h
int 21h

mov bx, 0h
mov bl, len2
mov s2[bx], '$'

mov cx, 32
lea si, num1
add si, 2
lea di, num2
add di, 2

mov cl, len1
mov ch, len2

cmp ch, cl
jb LESSTHAN
ja GREATERTHAN

je COMP

COMP:
mov al, [si]
mov ah, 00h
mov dl, [di]
mov dh, 00h
cmp ax, dx
ja LESSTHAN
jb GREATERTHAN
inc si
inc di
loop comp

je EQUAL

EQUAL:
mov ah, 09h
lea dx, equalMsg
int 21h
mov ah, 4ch
int 21h

LESSTHAN:
mov ah, 09h
mov dx, offset num1
add dx, 2
int 21h
mov ah, 4ch
int 21h

GREATERTHAN:
mov ah, 09h
mov dx, offset num2
add dx, 2
int 21h
mov ah, 4ch
int 21h

begin endp
end begin


here's my code for comparing 2 numbers and output which number is greater.hope it helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.