Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing from asm function

102 views
Skip to first unread message

gtb

unread,
Dec 26, 2007, 11:18:02 AM12/26/07
to
Greetings,

Just getting back to assemby after 10+ years away from it and trying
to learn a bit about x86 programming. My last experience was with a
Z80 so I am finding a lot of great things like MASM and HLA.

I was using the snippet below to test printing messages from an asm
function. How does one print <CRLF>? Adding 0x0D0A to the string does
not work, nor does '\n'.

I copied the MessageBox invocation from another example and I have all
the same includes and tried to run it under Vc++. But as you can see
it is commented as it was reported as an undefined symbol.

Lastly if one is developing for the IA-32 platform using an XP pc,
what are the assemblers and/or IDEs of choice at this time?

Thanx,

gtb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.486
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

.data
helloString db "Hello World! ",0
.code

fn1 proc
;invoke MessageBox, NULL, addr helloString, addr helloString, MB_OK
invoke StdOut, addr helloString
ret
fn1 endp

end

gtb

unread,
Dec 26, 2007, 3:19:14 PM12/26/07
to
Looks like adding a line feed with 0Ah works, tho I thought I would
need 0Dh as well. Still have the other 2 questions tho.

> helloString db "Hello World!", 0Ah,0

Tim Roberts

unread,
Dec 26, 2007, 11:40:50 PM12/26/07
to
gtb <spam...@crayne.org> wrote:
>
>Just getting back to assemby after 10+ years away from it and trying
>to learn a bit about x86 programming. My last experience was with a
>Z80 so I am finding a lot of great things like MASM and HLA.
>
>I was using the snippet below to test printing messages from an asm
>function. How does one print <CRLF>? Adding 0x0D0A to the string does
>not work, nor does '\n'.

It's a byte string, so 0x0D0A will be truncated to 0x0A. However, your
sentiment is correct:

helloString db "Hello World! ", 13, 10, 0
-- or --
helloString db "Hello World! ", 0dh, 0ah, 0

>I copied the MessageBox invocation from another example and I have all
>the same includes and tried to run it under Vc++. But as you can see
>it is commented as it was reported as an undefined symbol.

MessageBox and friends are in user32.inc. Add:

include \masm32\include\user32.inc
-- and --
includelib \masm32\lib\user32.lib

>Lastly if one is developing for the IA-32 platform using an XP pc,
>what are the assemblers and/or IDEs of choice at this time?

Choice of who? ;) I use masm and vim, the World's Greatest Editor.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

João Jerónimo

unread,
Dec 27, 2007, 10:56:48 AM12/27/07
to


Has to do with the terminal who is interpreting the stream your program prints:
- On Unixes, you only need a Line Feed.
- On DOS-based terminals (*DOS, windows and frinds), Line Feed just pushes
the cursor one step down, and Carriage Return puts it in the 1st column.
- On MasOS X, Carriage Return handles everything.

However, simply putting 0x0A0D in a byte string declaration won't work for
most assemblers. You have to separate the control codes:

db "something", 0Ah, 0Dh, 0
OR
db "something", 0x0A, 0x0D, 0

JJ

gtb

unread,
Dec 27, 2007, 8:09:10 PM12/27/07
to
Thanks folks, good info.

Might I now ask what are the idioms for printing register or memory
values?

Also I am using Visual C++ as I had it handy and figure that most asm
functions I develop would be called from C anyway. So I am using MASM
constructs, macros I suppose and just compiling and running my
programs as usual. It works but I confess I don't know what I or MASM
are doing.

Is there a way to see the actual code that MASM generates?

Can one run a debugger when running an asm function called from C/C++?

Thanx,
gtb

Dirk Wolfgang Glomp

unread,
Dec 28, 2007, 5:27:30 AM12/28/07
to
Am Thu, 27 Dec 2007 15:56:48 +0000 schrieb João Jerónimo:
> - On DOS-based terminals (*DOS, windows and frinds), Line Feed just pushes
> the cursor one step down, and Carriage Return puts it in the 1st column.

CR pushes the cursor one step down and LF puts it in the 1st colum?

Dirk

Betov

unread,
Dec 28, 2007, 2:32:36 AM12/28/07
to
gtb <spam...@crayne.org> écrivait news:1357aa1b-383a-413a-859d-
c37640...@j64g2000hsj.googlegroups.com:

> Is there a way to see the actual code that MASM generates?

With this question, you are just demonstrating to yourself
that MASM is *not* an Assembler.


Betov.

< http://rosasm.org >

Frank Kotler

unread,
Dec 28, 2007, 3:54:52 PM12/28/07
to

But surely the question has an answer! (not a user, but try "/l
myprog.lst") Then you can see the code that Masm actually generated - in
zero clicks!!!

Best,
Frank

João Jerónimo

unread,
Dec 28, 2007, 8:31:09 PM12/28/07
to
Dirk Wolfgang Glomp wrote:
>> - On DOS-based terminals (*DOS, windows and frinds), Line Feed just pushes
>> the cursor one step down, and Carriage Return puts it in the 1st column.
>
> CR pushes the cursor one step down and LF puts it in the 1st colum?

No. The other way!

" Hello"
| |
| Hello_ |
| |

LF:
| |
| Hello |
| _ |

CR:
| |
| Hello |
|_ |

"something":
| |
| Hello |
|something_ |

JJ

Tim Roberts

unread,
Dec 28, 2007, 11:59:44 PM12/28/07
to
gtb <spam...@crayne.org> wrote:
>
>Might I now ask what are the idioms for printing register or memory
>values?

If you are going to call your MASM code from C, you can just call printf.
If not, you can get the MASM distribution from www.masm32.com; he includes
a run-time library that has a lot of these functions.

>Is there a way to see the actual code that MASM generates?

The /FAsc parameter to ml.exe gets you the maximum listing.

>Can one run a debugger when running an asm function called from C/C++?

Sure. VC++ has a "disassembly" view that shows you each instruction.

Tim Roberts

unread,
Dec 29, 2007, 12:28:31 AM12/29/07
to
gtb <spam...@crayne.org> wrote:
>
>Is there a way to see the actual code that MASM generates?

I believe I just told you to use /FAsc. That is wrong; that's for Visual
C++. For MASM, you want /Fl /Sa.

H. Peter Anvin

unread,
Dec 29, 2007, 8:22:40 PM12/29/07
to

No, the other way around, as João said.

-hpa

Dirk Wolfgang Glomp

unread,
Dec 31, 2007, 3:47:25 AM12/31/07
to

Ok thanks.

Dirk

0 new messages