0

.model small .stack 100h .data

e db "Even Number$" o db "Odd Number$"

.code

Start:

Mov ax,@data
Mov ds,ax

Mov ah,01
int 21h

Mov bl,2
div bl

cmp ah,0
je eve

Mov ah,02
Mov dl,0AH
int 21h

Mov dx,offset o
Mov ah,09
int 21h

Mov ah,4ch
int 21h

eve:
    
Mov ah,02
Mov dl,0AH
int 21h


Mov dx,offset e
Mov ah,09
int 21h

Mov ah,4ch
int 21h 

end start

I am confused about this block of code
Mov bl,2 div bl I use this div as a modulo The confusion is how this is used as modulo because in divide if we do 2/2 so answer will be 1 so how the output is appeared as even number

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • The result in AH is the remainder, not the quotient. This is an inefficient way to test for odd with `test al, 1` or `and al, 1` / `jz even` to check the low bit. – Peter Cordes Apr 06 '21 at 06:25
  • can you please tell me which one is efficient way to test even odd?? – Abdul Majeed Apr 06 '21 at 14:36
  • Oops, sorry for the unclear phrasing. `test al, 1` / `jz even` *is* efficient. So is `and al, 1` if you want a 0 or 1 in a register, instead of just a FLAGS result. TEST is just AND that only writes FLAGS, not the first operand, so they're both fast. `div` is slowest integer instruction, by a large margin. See https://uops.info/ and https://agner.org/optimize/ – Peter Cordes Apr 06 '21 at 14:40

0 Answers0