comparing an array in assembly language

Thread Starter

cupcake

Joined Sep 20, 2010
73
Hi, I wanna ask.. suppose I have an array and a constant called threshold in my data segments


array db 1,2,3,4,5,6
threshold equ 5

I want to compare my array elements with the constant, and only display/print the number which is less that the threshold, if there are none, display the none message

this is what I have done so far...I got error messages regarding the bold one

start2:
mov ax, threshold
mov al, array[bx]
mov bx,al
cmp al,ax
jl print
dec al
jnz start2

print:
add bx,30h
mov al,array[bx] ;store the number at the array
mov ah,2 ;display the number at the screen
mov dl,al
add dl,30h
int 21h
inc bl ;increment index register
jnz print

can someone enlighten me?
 

cjdelphi

Joined Mar 26, 2009
272
start2:
mov ax, threshold
mov al, array[bx]

That's the issue, AL,AH are 8 bit registers, so when you move the threshold into ax..

ax = 5

now when you move the value off the array into al... AX becomes null you just overwrote the register!

mov al,threshold
mov ah,array[bx]

then

cmp al,ah
jle to print.... etc.
 

cjdelphi

Joined Mar 26, 2009
272
If the compiler does not allow it, push it onto the stack and pop it or use some other way around it by using 2 16 bit registers.
 

Thread Starter

cupcake

Joined Sep 20, 2010
73
ok, seems the compiler doesn't allow it..

so, how I'm gonna use the pop and stack? I'm not so familiar with it..
 

Thread Starter

cupcake

Joined Sep 20, 2010
73
here is my revision code

Rich (BB code):
count equ 6

start:
	mov ax,data ;initialise data segment
	mov ds,ax
	
	xor	ch,ch		;initialize counter
	mov	cl,count	
	xor	bx,bx		;initialize index register	
		

start2:
	mov dl,10d ;display line
	mov ah,2h
	int 21h
	mov al,array[bx]
	mov ah,threshold
	cmp al,ah
	jl print
	inc bl
	dec cl
	jnz start2

print:
	mov	ah,2
	mov al,array[bx]	;display data on screen
	add al, 30h
	int 21h
	dec	bl		;next piece
	inc cl
	jnz	print
I'm not sure what I'm doing with the red portion, I'm thinking to increase the index register, so that I could traverse along the array and check the element what by one, but I think I didn't do it correctly since it's not working... any advise?
 
Top