Author Topic: need help with segment .bss "variables"  (Read 7502 times)


  • Guest
need help with segment .bss "variables"
« on: March 19, 2005, 10:18:44 AM »
i have a problem with the .bss segment..

temp1 db 4 <----- an example of what i did

and in the .text segment in the middle of my program i initiated the 0x0A into AH so i could store keystrokes
its like this

*mov DX,109   <--- i have a problem with this one. this is from debug and i cant translate it to nasm. 0109 is supposedly the starting address where the keystrokes will be stored
mov AH,0x0A
int 0x21

i dunno how to get that data back and store it to my temp1 variable. help pls.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2429
  • Country: us
Re: need help with segment .bss "variables"
« Reply #1 on: March 19, 2005, 11:20:23 AM »
Well... first the .bss section... It's for uninitialized data. With "temp1 db 4", you're trying to initialize one byte with the value 4. In .bss, you want "temp1 resb 4" - that reserves 4 bytes.

Dos int 21h/0Ah expects the address of a "special" buffer - the first byte *must* be filled in with "maximum count", the second byte is "reserved" for the "actual count" of characters entered, input is stored starting at the third byte. So you've got to either use an initialized buffer, with "max count" filled in, or stuff the "max count" into the first (zero-th) byte of an uninitialized buffer.

You could, if you like pain, do it "DEBUG-style", and do "mov dx, 109h", but Nasm is a symbolic assembler, and will understand "mov dx, temp1".

section .bss

temp1 resb 4 ; better to "%define MAXINPUT 4"

section .text

mov byte [temp1], 2  ; MAXINPUT - 2
mov ah, 0Ah
mov dx, temp1
int 21h

Now dos waits for input - with a buffer size of 4, you only get *one* character stored - one byte is "max count", one is "actual count", and as I recall, dos *always* stores the carriage return that terminates input. So you probably want a bigger buffer - 7 bytes, if you need 4 characters of input.

Note that this isn't terminated with "$", so take care of that if you plan to use int 21h/9 to display it!



  • Guest
Re: need help with segment .bss "variables"
« Reply #2 on: March 19, 2005, 11:52:10 AM »
ya about resb.. i had it.. i may hav just been thinking of db... my bad.


  • Guest
Re: need help with segment .bss "variables"
« Reply #3 on: March 21, 2005, 05:04:11 AM »
temp1 resb 4 <--- this will reserve 4 bytes right?? so it means 2 words
temp2 resb 4
temp3 resb 4

how will i be able to swap values between temp1 and temp2 using temp3 as a temporary buffer for the values of temp1?? im having trouble to how i should swap it...

im thinkin about loading the address of temp1 do dx so i could point it and store the values to temp3 then loop it again. then do the same to temp2.. i can only think of how to do it.. but i cant actually do it.. im kinda braindead. tnx for any help.