943,948 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1351
  • Assembly RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Aug 17th, 2009
0

Re: Assembly wierdness

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.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Aug 17th, 2009
0

Re: Assembly wierdness

my gcc port is DJGPP i think
how do i adjust the stack?
Last edited by tomtetlaw; Aug 17th, 2009 at 7:11 pm.
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008
Aug 17th, 2009
0

Re: Assembly wierdness

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.

Assembly Syntax (Toggle Plain Text)
  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
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Aug 18th, 2009
0

Re: Assembly wierdness

I ran your code and it doesn't do anything

This is my code, the same thing but without the functions:
asm Syntax (Toggle Plain Text)
  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.
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008
Aug 18th, 2009
0

Re: Assembly wierdness

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.
Reputation Points: 99
Solved Threads: 5
Junior Poster
Evenbit is offline Offline
140 posts
since Mar 2005
Aug 18th, 2009
0

Re: Assembly wierdness

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.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Aug 19th, 2009
0

Re: Assembly wierdness

i don't know what my compiler uses
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Win32 functions in NASM
Next Thread in Assembly Forum Timeline: assembly switch/case macro





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC