Prev: Sudoku
Next: Linux distro request
From: Robert Redelmeier on 30 Mar 2008 12:55 ivanatora <ivanatora(a)gmail.com> wrote in part: > You mean you declare variables after you use them? > It is kinda weird :) Fully agreed. Declaring variables at all is very wierd :) Sooner or later, they'll get defined. "Strong typing is for people with weak minds [?]" > Nevermind, I tried that - moved section .bss after .text. Also > increased bytes for 'i' to 4, but I think 1 byte is enough for that > attempt. > The result from that is half good, half bad. > Now mov byte [i],65 works fine! > But inc byte [i] - doesn't work fine and the result is 'Killed' again. Really wierd. I presume by[i] is already written before the `inc`. Otherwise it will read from the zero page (where .bss is mapped prior to writing). > I've put a breakpoint on a nop before _start and run gdb, > but the program gets killed before reaching the _start point. So perhaps something is odd about the ELF header. `ld` doesn't load anything, it just produces the binary. `bash` or some other shell does the exec() to run the pgm, and exec() doesn't like something about that binary. -- Robert
From: Robert Redelmeier on 30 Mar 2008 13:01 Frank Kotler <fbkotler(a)verizon.net> wrote in part: > Robert Redelmeier wrote: >>>section .bss >>> i resb 1 >> Why so small? This ain't the 8088. >> Excessive cheapness always produces breakage and rework. > > Bloat! Bloat! Bloat! :) > Seriously, a byte ought to be enough... No, it needs to live on a separate 4kB page. -- Robert
From: Frank Kotler on 30 Mar 2008 14:08 Robert Redelmeier wrote: > Frank Kotler <fbkotler(a)verizon.net> wrote in part: > >>Robert Redelmeier wrote: >> >>>>section .bss >>>> i resb 1 > > >>>Why so small? This ain't the 8088. >>>Excessive cheapness always produces breakage and rework. >> >>Bloat! Bloat! Bloat! :) >>Seriously, a byte ought to be enough... > > > No, it needs to live on a separate 4kB page. Okay, two bytes, then. Or four... How many bytes is "enough" to cause it to live on a separate page? Best, Frank
From: Robert Redelmeier on 30 Mar 2008 14:26 Frank Kotler <fbkotler(a)verizon.net> wrote in part: > Okay, two bytes, then. Or four... How many bytes is "enough" > to cause it to live on a separate page? This should be handled by NASM, ld or exec() from the ELF header. AFAIK, in the binary, .bss ought just be visible as brk(), the end of the used memory. It might even start in a .data. page. The canonical order is .text, .rodata, .data, .bss, .stack . ..text and .rodata can transition on the same 4 kB page, as can .data and .bss. Deviate at your peril. -- Robert
From: ivanatora on 30 Mar 2008 14:33
Mistery is going deep and deep, or I am completely out of skills: That code should print '2' (ascii 50) twice give KILL: ----------------------------------------------- section .text global _start _test: nop _start: nop _bla: mov byte [i],50 mov eax, 0x04 mov ebx, 0x01 mov ecx, i mov edx, 1 int 80H mov eax, 0x04 ; I load EAX again, becouse the exit status from the last syscall is written in EAX ; I'm wondering what happens to the memory at 'i' ? Maybe it got overwritten with some other exit/status code? ; mov [i],49 ; if I uncoment that, I got '21' printed on the screen - EXACTLY as expected - with no kill int 80H mov eax, 0x01 int 80H section .bss i resb 4 ----------------------------------------------- |