Note that there are some explanatory texts on larger screens.

plurals
  1. POData segment issue with x86 Assembler (nasm) for print function
    primarykey
    data
    text
    <p>I am currently playing around with x86 assembler since I wanted to refresh my skills for low level programming :-). For testing purposes I tried to write a function that just prints out a given string. The printing function itself works fine. In a further step I wanted to load a second assembler program from disk jump to it and just print out a text. Loading from disk at jump to the address works fine.</p> <p>Here is the given scenario:</p> <pre><code>[... loading from disk etc ... program is loaded to 0x7e0:0001] jmp 0x7e0:0001 [... context of other asm ...] jmp Start ;data fields msg db "Hello World!",0 Start: xor si, si ; clear SI register mov si, msg ; load message to SI register call Print cli hlt ; halt the system Print: .PrintLoop: lodsb ; load byte from SI register or al, al ; check if 0 byte jz short .PrintDone ; if so - stop mov ah, 0Ah ; function - print text to cursor int 0x10 ; BIOS interrupt jmp .PrintLoop ; continue with next char .PrintDone: ret </code></pre> <p>All of this program is working fine. The only problem that I face is, that no text is printed. During debugging I saw that the print function immediately jumps to the .PrintDone label since there seems to be no data in SI and therefore lodsb loads nothing to al (besides null byte).</p> <p>I was thinking about the fact, that there might be something wrong with the data segment.</p> <p>Thus, I added the following line at the beginning of the Start-Routine:</p> <pre><code>xor ax, ax ; clear ax register mov ax, cs mov ds, ax ; set data segment pointer </code></pre> <p>But this changed nothing regarding the programs behaviour. Nothing is printed.</p> <p>Inspecting the CPU registers when execution reaches halt instruction, gives the following:</p> <pre><code>EAX=00000a00 EBX=00000000 ECX=00000002 EDX=00000000 ESI=00000026 EDI=00000000 EBP=00000000 ESP=0000ffff EIP=00000036 EFL=00000046 [---Z-P-] CPL=0 II=0 A20=1 SMM=0 HLT=1 ES =07e0 00007e00 0000ffff 00009300 CS =07e0 00007e00 0000ffff 00009b00 SS =9000 00090000 0000ffff 00009300 DS =07e0 00007e00 0000ffff 00009300 </code></pre> <p>Do you have any clue what's going on here?</p> <p><strong>[EDIT - PROBLEM RESOLVED]</strong></p> <p>Replacing:</p> <pre><code>mov ah, 0Ah -&gt; mov ah, 0xE </code></pre> <p>fixes the problem!</p> <p>Best Sebastian</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload