Task

Test whether an integer is even or odd.

There is more than one way to solve this task:

 Use the even and odd predicates, if the language provides them.
 Check the least significant digit. With binary integers, i bitwise-and 1 equals 0 iff i is even, or equals 1 iff i is odd.
 Divide i by 2. The remainder equals 0 iff i is even. The remainder equals +1 or -1 iff i is odd.
 Use modular congruences:
 i ≡ 0 (mod 2) iff i is even.
 i ≡ 1 (mod 2) iff i is odd.


CMDLIN:	equ	80h		; Location of CP/M command line argument
puts:	equ	9h		; Syscall to print a string
	;;;	Check if number given on command line is even or odd
	org	100h
	lxi	h,CMDLIN	; Find length of argument
	mov	a,m		
	add	l		; Look up last character (digit)
	mov	l,a
	mov	a,m		; Retrieve low digit
	rar			; Rotate low bit into carry flag
	mvi	c,puts		; Prepare to print string
	lxi	d,odd		; If carry is set, then the number is odd
	jc	5		; So print 'odd'
	lxi	d,even		; Otherwise, the number is even
	jmp 	5		; So print 'even'
even:	db	'Even$'		; Strings
odd:	db	'Odd$'