flat assembler
Message board for the users of flat assembler.

Index > Main > Bug that causes jmp to ecx?

Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 03 Dec 2010, 03:28
Here's my code. I'm executing it in Qemu and it aborts because my code tries to execute an uninitialized address. I noticed in the reg dump that EIP always equals ECX when it aborts, but I can't find the relation.

Code:
format binary as 'bin'
org 7C00h
use16

   jmp       main
   nop

main:
   mov       ebx,10*18

   call      delay

   hlt


; ebx = seconds to wait / 18.2
delay:
   pusha
   mov       ebp,esp
   sub       esp,4
   label     .lo word at ebp - 2
   label     .ho word at ebp - 4

   mov       eax,0
   int       1ah

   add       edx,ebx

   mov       [.lo],dx
   mov       [.ho],cx

   .longer:
      mov       eax,0
      int       1ah

      cmp       [.ho],cx
      ja        .done

      cmp       [.lo],dx
      ja        .done

      cmp       al,1
      jne       .longer

   .done:

   mov       esp,ebp
   popa

   ret

times 510-($-$$) db 0
dw 0AA55h
    
Post 03 Dec 2010, 03:28
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 03 Dec 2010, 10:50
Tyler,

Under Bochs it works as written. Pun intended: that code looks like weird mix of 16/32-bit instructions (e.g. cx isn't high word of edx as one may suppose looking at it).

Probably QEMU stumbles upon this. I'm using Bochs because it (1) is x86-centric, and (2) supports debugging natively.
Post 03 Dec 2010, 10:50
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 06 Dec 2010, 21:56
Okay, so I'll try to change it to the 16bit alternatives. Bochs is okay, but... I prefer Qemu. Not sure why, maybe because it's more Linux-centric.
Post 06 Dec 2010, 21:56
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.