flat assembler
Message board for the users of flat assembler.

Index > Main > Incrementing counter variable

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Hey, I'm trying to use buffered input with BIOS int 16h, AH = 00. The thing is I have a buffer variable, but I don't know how I can increment it's memory address each time I go through a function.

Ie.


Start:
mov ah, 00h
int 16h
mov [buffer], al
inc buffer ; Doesn't work!
jmp Start


Help would be greatly appreciated

Thanks.

-Rhyno
Post 07 Dec 2006, 23:10
View user's profile Send private message Reply with quote
Kenneth



Joined: 16 Nov 2005
Posts: 38
Location: United States of America
Kenneth
Code:
inc [buffer]    
?
Post 07 Dec 2006, 23:57
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Wouldn't that increment the value that's inside the buffer as opposed to the memory address?
Post 08 Dec 2006, 00:03
View user's profile Send private message Reply with quote
Kenneth



Joined: 16 Nov 2005
Posts: 38
Location: United States of America
Kenneth
Hmm, I suppose it would. My bad, didn't really read. Spent more time looking at your code.
Post 08 Dec 2006, 00:33
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
If you want the C code "*(pBuffer++) = al" then you need this
Code:
mov bx, [pBuffer]
mov [bx], al
inc [pBuffer]    


pBuffer should be initialized somewhere with a pointer to the buffer memory area.
Post 08 Dec 2006, 00:36
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks! When you do the move routine does it copy the actual value or the memory address though? That's what I'm wondering now from looking at that code
Post 08 Dec 2006, 00:57
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Code:
    mov   di,BufferStart:    mov ah, 00h    int 16h    mov [es:di], al    inc di     cmp al,'q'    jne Start     
Post 08 Dec 2006, 01:04
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks Dex
Post 08 Dec 2006, 01:06
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
; ASM              | C
mov bx, pBuffer    ; bx = &pBuffer
mov bx, [pBuffer]  ; bx = pBuffer
mov [bx], al       ; *bx = al
    


That answer you question? (no sure what you're asking actually Razz)
Post 08 Dec 2006, 01:07
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
The question is how can I get the ASM version of this:
Code:
pBuffer = bx //pBuffer contains memory address of bx
    
Post 08 Dec 2006, 02:04
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
if pBuffer contains memory address of bx then why you want to store it again?

Anyway I'll "compile" what I'm seeing
Code:
mov [pBuffer], bx    


BTW, note that my previous C examples assumes bx as the register bx, if it were a memory operand then
Code:
; *pBuffer = b
mov bx, [pBuffer]
mov ax, [b]
mov [bx], ax    
Post 08 Dec 2006, 04:12
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
[quote = "LocoDelAssembly"]if pBuffer contains memory address of bx then why you want to store it again? [/quote]

It doesn't. I'm trying to get the address contained in bx to be the one of pBuffer
Post 08 Dec 2006, 12:50
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Well is the first code of the previous post. I think you are wanting to make something like "mov pBuffer, bx" which is imposible because pBuffer is a label, you need to have a variable that holds a pointer and do the second code.

To clarify I'll write again your code using 'q' as escape condition like Dex did
Code:
mov bx, [pBuffer]
Start: 
cmp bx, buffer+256
je exit
mov ah, 00h
int 16h
mov [bx], al
inc bx
cmp al, 'q'
jne Start
exit:
mov [pBuffer], bx
.
.
.
pBuffer dw buffer
buffer rb 256 ; 256 bytes buffer
    
Post 08 Dec 2006, 14:32
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
That's what I was looking for! Thanks! Very Happy
Post 08 Dec 2006, 14:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.