NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Gunner on November 14, 2014, 03:58:45 AM
-
Let's say I have a string defined as such:
szErrInvalidEmailLen db "Email entered is too long, valid is less than 260 characters", 0
is there anyway to change the 260 to something like this:
szErrInvalidEmailLen db "Email entered is too long, valid is less than MAX_EMAIL_LEN characters", 0
where MAX_EMAIL_LEN is defined as MAX_EMAIL_LEN equ 25
So, if I change MAX_EMAIL_LEN it will reflect in the string?
-
My suggestion:
%defstr MAX_EMAIL_LEN 25
szErrInvalidEmailLen db "Email entered is too long, valid is less than ", MAX_EMAIL_LEN, " characters", 0
-
My suggestion:
%defstr MAX_EMAIL_LEN 25
szErrInvalidEmailLen db "Email entered is too long, valid is less than ", MAX_EMAIL_LEN, " characters", 0
That suggestion is not going to work at all. The defined value does not correlate to the proper ASCII value for display purposes.
What actually needs to occur is similar to the following C code:
#define MAX_EMAIL_LEN 25
char buf[260];
sprintf(buf, "Email entered is too long, valid is less than %d characters", MAX_EMAIL_LEN);
-
Yes, I know about the printf family of functions; I was hoping for some preprocessor magic.
-
If you use a macro like this, you'll have to change only one value.
%macro equstr 1
%00 equ %1
%defstr %00_STR %1
%endmacro
MAX_EMAIL_LEN equstr 25
; now use MAX_EMAIL_LEN as normal equate and MAX_EMAIL_LEN_STR as a string representation
[SECTION .data]
szErrInvalidEmailLen db "Email entered is too long, valid is less than "
db MAX_EMAIL_LEN_STR
db " characters", 0
-
Thanks, works perfectly!
That suggestion is not going to work at all. The defined value does not correlate to the proper ASCII value for display purposes.
I just tried the suggestion from rkhb and it does work. Dunno..
-
You are correct. I mistook the defstr for define. However, gammac's suggestion is better as you get both a numeric and a string value to use throughout your source files.