View Single Post
Old 06-20-2004, 03:03 PM   #1 (permalink)
Amaranthine
Registered User
 
Amaranthine's Avatar
 
Join Date: May 2004
Posts: 47
Amaranthine is on a distinguished road
Red face Writing a binary value

I am practicing writing some simple but useful procedures for my x86 assembly stuff. I have tested this and it works fine, but whenever I use any sort of and, neg, or, xor instruction it does strange things to the value that I do it to.
I can't figure out if it is my procedure to write the value to the console that is screwy, or if I am just making a dumb mistake.
Code:
WriteBin proc
	; save registers
	push cx
	push dx
	push si

	mov cx,16	; number of bits to display
	
	mov si,OFFSET bBuffer
	_WRITE:
		shl ax,1	; shift bit into carry field
		mov BYTE PTR [si],'0'
		jnc _ZERO ; is it a zero?
		mov BYTE PTR [si],'1' ; no, change it to 1
	_ZERO:
		inc si		; increment cx
	loop _WRITE
	; Display the binary value in bBuffer
	mov dx,OFFSET bBuffer
	mov cx,LENGTHOF bBuffer
	call WriteString ; another function I made that outputs a string pointed to by dx
	; restore registers
	pop si
	pop dx
	pop cx
	ret
WriteBin endp
The following code produces this output:
0000000000000001
0000000000000000
Code:
; other stuff (taken out to shorten)
main proc
	mov ax,@data	; set up segment
	mov ds,ax
	
	mov ax,1
	call WriteBin
	endl ; A macro I made that outputs a new line
	and ax,1
	call WriteBin
	.exit
main endp

; other code (taken out to shorten)
Maybe I am overlooking something stupid but shouldn't "and 1,1 = 1"?
So can anyone see a problem with my WriteBin procedure or some other stupid mistake? This has really started to agitate me.
(I am using masm as my assembler)

Thanks

Last edited by Amaranthine; 06-20-2004 at 03:46 PM.
Amaranthine is offline   Reply With Quote