Skip to content

Instantly share code, notes, and snippets.

@quickgrid
Created March 14, 2016 16:38
Show Gist options
  • Save quickgrid/fe69d9fda130c8439fb0 to your computer and use it in GitHub Desktop.
Save quickgrid/fe69d9fda130c8439fb0 to your computer and use it in GitHub Desktop.
This 8086 assembly code checks even or odd and prints their output. The code is explained in comments line by line.
;Author:quickgrid
;Site: http://quickgrid.blogspot.com
;Code: Even odd check 8086 assembly code
;predefined macro for speed coding
;define any code here that is reduandant
newline macro
lea dx,nl
mov ah,9
int 21h
endm
.model small
.stack 100h
.data
;remermber to put a $ after or if you want it
;keep executing than put it on other line
msg1 db 'number is even', '$'
msg2 db 'number is odd', '$'
nl db 0dh,0ah, '$'
.code
.startup
;initialize data segment
mov ax,@data
mov ds,ax
;ah=1 is take input, int 21h execute above command
mov ah,1
int 21h
;divide al by whatever is in bl
mov bl,2
div bl
;ah contains remainder after division, al contains the operand, no need for
;operand anymore replace with remainder
mov al,ah
;check if remainder is zero
cmp al,0
;use any condition here jump greater, jump if not equal etc
jg odd
;if it was a odd number than it would never reach here
;print a new line if even
even:
newline
;print the string in msg1 and skip rest of the code to exit label
lea dx,msg1
mov ah,9
int 21h
jmp exit
;the previous jg odd label jumps to here skipping even portion of the code
odd:
newline
;show the message for odd number
lea dx,msg2
mov ah,9
int 21h
;just a jump label to skip executing some codes
exit:
.exit
@ya-shuvo30
Copy link

ya-shuvo30 commented Jul 16, 2021

Thanks for giving this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment