Assembly wierdness

Reply

Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Assembly wierdness

 
0
  #11
Aug 17th, 2009
Almost all of these beginners are using 16-bit REAL Mode versions of the assembler. Very few are actually using 32-bit.

I am very aware of Virtual Memory, Code Segments, Data Segments, Stack Segments, Extra Segments, etc. Come from different physical memory in a 32-bit model. You can use 32-bit registers in REAL mode provided the processor is a 386 or above. There were no clear indications in their code that his person is pure Protected Mode. Granted they didn't have the tell-tale .ORG $100

Okay in reviewing his code, his crash dump clearly shows he's using 32-bit code!
Last edited by wildgoose; Aug 17th, 2009 at 7:07 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 369
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: Assembly wierdness

 
0
  #12
Aug 17th, 2009
my gcc port is DJGPP i think
how do i adjust the stack?
Last edited by tomtetlaw; Aug 17th, 2009 at 7:11 pm.
...
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Assembly wierdness

 
0
  #13
Aug 17th, 2009
I installed MinGW since I'm running windows to get the GNU compiler for Windows.
And I modified your code. Your code would run but would crash in the end. I added returns to each function so it wasn't printing all the functions each time. Adding the return to _main solved the crash. It appears NASM-with the Win library doesn't need the .START declaration as it appears to be calling the procedure _main.

  1. [section .data]
  2. hello: db 'Hello world!', 10, 0 ;15 bytes
  3. nl: db ' ', 10, 0 ;3 bytes
  4.  
  5.  
  6.  
  7. [section .text]
  8.  
  9. global _main, _print_nl, _print_msg, _return
  10. extern _printf
  11.  
  12.  
  13.  
  14. _print_nl:
  15. push nl
  16. call _printf
  17. add esp, 4
  18. ret
  19.  
  20. _print_msg:
  21. push hello
  22. call _printf
  23. add esp, 4
  24. ret
  25.  
  26. _return:
  27. mov eax, 0
  28. ret
  29.  
  30.  
  31. _main:
  32. call _print_msg
  33. call _print_nl
  34. call _print_msg
  35. call _return
  36.  
  37. ret
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 369
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: Assembly wierdness

 
0
  #14
Aug 18th, 2009
I ran your code and it doesn't do anything

This is my code, the same thing but without the functions:
  1. [section .data]
  2. hello: db 'Hello world!', 10, 0 ;15 bytes
  3. nl: db ' ', 10, 0 ;3 bytes
  4.  
  5. [section .text]
  6. global _main
  7. extern _printf
  8.  
  9. _main:
  10. push hello
  11. call _printf
  12. add esp, 4
  13.  
  14. push nl
  15. call _printf
  16. add esp, 4
  17.  
  18. push hello
  19. call _printf
  20. add esp, 4
  21.  
  22. mov eax, 0
  23. ret
Last edited by tomtetlaw; Aug 18th, 2009 at 3:32 am.
...
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 129
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster

Re: Assembly wierdness

 
0
  #15
Aug 18th, 2009
wildgoose -

Please consult the Narue tutorial that tomtetlaw was talking about:

http://www.daniweb.com/forums/thread41309.html

Pay attention to the discussion of the C calling convention.
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Assembly wierdness

 
0
  #16
Aug 18th, 2009
So EvenBit. I read the pdf. Read the NASM documents. My modified version of tomtetlaw's code works on the NASM and MinGW installations I had to install just to run his code, and it ran! I am using the standard C method CDECL calling conventions, just like in the PDF. I have no idea why his code doesn't run unless he has a different version of GNU which has other requirements. Except for a few quirks, NASM is similar to MASM, which is my primary assembler and that I have been programming professionally for a very long time.

Is the compiler he's using using fastcall, or stdcall instead of cdecl? CDECL is typically a C languge method.

So enlighten me please!
Last edited by wildgoose; Aug 18th, 2009 at 3:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 369
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: Assembly wierdness

 
0
  #17
Aug 19th, 2009
i don't know what my compiler uses
...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC