Assembly and C programs to count number of negative 8-bit numbers
from 0xE000 to 0xEFFF
Assemble language program
; Program to count negative 8-bit numbers
; from 0xE000 to 0xEFFF
; Bill Rison
; 2/15/98
.title COUNT NEG NUMBERS
EVBRAM = 0x0000 ;0x0000 is start of user ram on 68HC11EVBU
DATA = EVBRAM
PROG = EVBRAM+0x100 ;start program above BUFFALO
START = 0xE000 ;start of table
END = 0xEFFF ;end of table
.area CODE (ABS)
.org PROG ;set program counter to 0x0100
start: ldx #START ;Reg X points to entry to process
ldy #0 ;Hold sum in Y -- clear to start
l1: brset 0,x,#0x80,l2 ;If entry is positive (MSB=0), don't sum
iny ;Add to count in Y
l2: inx ;REG X points to next entry in table1
cpx #END ;Has pointer gone past end of table?
bls l1 ;If not done, process next table entry
sty count ;Save result
swi ;Done -- Exit
.area DATA (ABS)
.org DATA
count: .ds 2
C language program using do {} while (); form
/*
* Program to count the number of
* 8-bit negative numbers from
* 0xE000 to 0xEFFF
*
* February 5, 1998 Bill Rison
*/
#define START 0xE000
#define END 0xEFFF
main()
{
int count;
char *ptr;
count = 0;
ptr = START;
do
{
if (*ptr < 0)
{
count = count + 1;
}
ptr = ptr + 1;
}
while (ptr <= END);
}
C language program using while () { } form
/*
* Program to count the number of
* 8-bit negative numbers from
* 0xE000 to 0xEFFF
*
* February 5, 1998 Bill Rison
*/
#define START 0xE000
#define END 0xEFFF
main()
{
int count;
char *ptr;
count = 0;
ptr = START;
while (ptr <= END)
{
if (*ptr < 0)
{
count = count + 1;
}
ptr = ptr + 1;
}
}