Skip to content

Instantly share code, notes, and snippets.

@douglas-vaz
Created July 25, 2012 10:03
Show Gist options
  • Save douglas-vaz/3175406 to your computer and use it in GitHub Desktop.
Save douglas-vaz/3175406 to your computer and use it in GitHub Desktop.
8086 Assembly count even and odd using RCR
include io.h
data SEGMENT
lf db 0dh,0
cr db 0ah,0
n_prompt db 'Enter size of array',0
el_prompt db 'Enter elements',0
odd_prompt db 'Odd = ',0
even_prompt db 'Even = ',0
n dw 40 dup(?)
foo dw 40 dup(?)
arr dw 100 dup(?)
data ENDS
code SEGMENT
ASSUME cs:code, ds:data
start: MOV ax,data
MOV ds,ax
output n_prompt
output cr
output lf
inputs foo,40
atoi foo
mov n,ax
lea bx,arr
mov dx,n
output el_prompt
output cr
output lf
__in: inputs foo,40
atoi foo
mov [bx],ax
add bx,2
dec dx
cmp dx,0
jne __in
lea bx,arr
mov ax,0 ;count for even
mov cx,0 ;count for odd
_count: mov dx,[bx]
add bx,2
dec n
rcr dx,1
jnc odd
inc ax
jmp __iter
odd: inc cx
__iter: cmp n,0
jne _count
output even_prompt
itoa foo,ax
output foo
output cr
output lf
output odd_prompt
itoa foo,cx
output foo
quit: mov al,0
mov ah,4ch
int 21h
code ends
end start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment