The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: m987 on March 18, 2012, 11:37:32 PM

Title: String program
Post by: m987 on March 18, 2012, 11:37:32 PM
Hi!  I have to write a program that defines symbolic names for several string literals, but my output does not appear on the cmd. I try to include INCLUDE Irvine32.inc, but this error appear multiple .Model directives found, help me please.

TITLE string (string.asm)
; This program defines symbolic names for several string literals

INCLUDE Irvine32.inc

.386
.Model flat, stdcall
string1 textequ <"Dog">
string2 textequ <"cat">

.data
prompt1 BYTE string1
prompt2 BYTE string2

.code
end

Title: Re: String program
Post by: MichaelW on March 19, 2012, 12:07:48 AM
In the irvine32.inc that I have the first statement is:

INCLUDE SmallWin.inc

And in SmallWin.inc:

.386
.MODEL flat, stdcall
.STACK 4096

So I think you need to remove the .MODEL directive from your source.

Also, when you define the strings in your data section, you need to add a null terminator, for example:

prompt1 BYTE string1,0

Title: Re: String program
Post by: dedndave on March 19, 2012, 12:49:46 AM
well - not all strings need to be terminated with a null
however, you will find it handy for many functions that might be used to display a string

in console mode, we typically use WriteFile to display strings
that function natively requires the length of the string
so - if you use the "sizeof" operator, the null terminator is not required

but - that is clumsy - if you display 100 strings, that is 100 times you have to supply the length
better to use a function that acquires the length of a null-terminated string
Title: Re: String program
Post by: MichaelW on March 19, 2012, 01:23:35 AM
At least most of the Irvine32 string-related procedures expect/return null-terminated strings.