The MASM Forum

General => The Campus => Topic started by: Timofeyka on July 13, 2021, 10:42:32 PM

Title: Variable output
Post by: Timofeyka on July 13, 2021, 10:42:32 PM
Hello.
I need help - I don't know how to print a variable through normal print, without masmBasic and kip irvines library. Who knows, tell me. :undecided:
Title: Re: Variable output
Post by: jj2007 on July 13, 2021, 10:44:07 PM
print str$(myvar), 13, 10
Title: Re: Variable output
Post by: Timofeyka on July 13, 2021, 10:44:56 PM
lol
Title: Re: Variable output
Post by: Timofeyka on July 13, 2021, 10:47:50 PM
Quote from: jj2007 on July 13, 2021, 10:44:07 PM
print str$(myvar), 13, 10
My code with this is not working
  .686
  .model flat, stdcall
  option casemap :none
  include C:\masm32\include\masm32rt.inc
  .data
    s db "SS",0
  .code
  main:
    print str$(s)
  end main
Title: Re: Variable output
Post by: jj2007 on July 13, 2021, 10:50:24 PM
include \masm32\include\masm32rt.inc

.data
myvar dd 12345

.code
start:
  print str$(myvar), " is the value of myvar", 13, 10
  inkey "press any key"
  exit

end start


Quote from: jj2007 on July 09, 2021, 06:47:06 PM
- use include \Masm32\include\..., not C:\Masm32; many members use other drives
Title: Re: Variable output
Post by: Timofeyka on July 13, 2021, 10:54:28 PM
Quote from: jj2007 on July 13, 2021, 10:50:24 PM
include \masm32\include\masm32rt.inc

.data
myvar dd 12345

.code
start:
  print str$(myvar), " is the value of myvar", 13, 10
  inkey "press any key"
  exit

end start


Quote from: jj2007 on July 09, 2021, 06:47:06 PM
- use include \Masm32\include\..., not C:\Masm32; many members use other drives

no errors, but no output
Title: Re: Variable output
Post by: jj2007 on July 13, 2021, 10:56:27 PM
- did you use "console assembly"?
- was an exe file created?
- did you see any error messages?
Title: Re: Variable output
Post by: Timofeyka on July 13, 2021, 11:25:22 PM
Quote from: jj2007 on July 13, 2021, 10:56:27 PM
- did you use "console assembly"?
- was an exe file created?
- did you see any error messages?
1. Yes(Subsystem in Link).
2. Yes.
3. No.
I have now specially compiled and linked manually.
Title: Re: Variable output
Post by: jj2007 on July 13, 2021, 11:28:00 PM
How many bytes does your executable have?
What exactly do you see when you run the exe from a DOS prompt?

The only reason I could imagine that you don't see anything would be an AV that silently blocks the exe.
Title: Re: Variable output
Post by: Timofeyka on July 13, 2021, 11:29:35 PM
Quote from: jj2007 on July 13, 2021, 11:28:00 PM
How many bytes does your executable have?
What exactly do you see when you run the exe from a DOS prompt?

The only reason I could imagine that you don't see anything would be an AV that silently blocks the exe.
The size is 2.50 kilobytes. I run the file from the console, half a second passes, and the program closes.
Title: Re: Variable output
Post by: jj2007 on July 13, 2021, 11:31:11 PM
Size is ok. Mysterious - please zip the exe and attach it to a post here.
Title: Re: Variable output
Post by: Timofeyka on July 13, 2021, 11:36:55 PM
Ok
Title: Re: Variable output
Post by: jj2007 on July 13, 2021, 11:55:33 PM
Thanks. You are victim of a very old MASM bug:
Address   Hex dump          Command                                  Comments
00401000  /$  68 03304000   push offset 00403003
00401005  |.  6A 00         push 0                                   ; /Arg2 = 0
00401007  |.  A0 00304000   mov al, [403000]                         ; |ASCII "SS"
0040100C  |.  66:0FB6C0     movzx ax, al                             ; |
00401010  |.  66:50         push ax                                  ; |Arg1<<<<<<<<<<<<<< BUG <<<
00401012  |.  E8 19000000   call 00401030                            ; \main.00401030


Use UAsm (http://www.terraspace.co.uk/uasm.html#p2).
Title: Re: Variable output
Post by: hutch-- on July 14, 2021, 12:06:03 AM
You may need to add that you don't normally PUSH a 16 bit register in 32 bit as an argument. He probably needs UASM where MASM requires correct code.
Title: Re: Variable output
Post by: jj2007 on July 14, 2021, 02:01:31 AM
Hutch,

This is the code that I proposed, and that he apparently used. No idea where the push ax comes from :cool:

include \masm32\include\masm32rt.inc

.data
myvar dd 12345

.code
start:
  print str$(myvar), " is the value of myvar", 13, 10
  inkey "press any key"
  exit

end start
Title: Re: Variable output
Post by: Vortex on July 14, 2021, 02:13:45 AM
Hi Timo,

Here is another example :

include     \masm32\include\masm32rt.inc

.data

var         dd  100
string      db 'var = %u',13,10,0

.code

start:

    invoke  crt_printf,ADDR string,var

    invoke  ExitProcess,0

END start
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:13:39 AM
Quote from: jj2007 on July 13, 2021, 11:55:33 PM
Thanks. You are victim of a very old MASM bug:
Address   Hex dump          Command                                  Comments
00401000  /$  68 03304000   push offset 00403003
00401005  |.  6A 00         push 0                                   ; /Arg2 = 0
00401007  |.  A0 00304000   mov al, [403000]                         ; |ASCII "SS"
0040100C  |.  66:0FB6C0     movzx ax, al                             ; |
00401010  |.  66:50         push ax                                  ; |Arg1<<<<<<<<<<<<<< BUG <<<
00401012  |.  E8 19000000   call 00401030                            ; \main.00401030


Use UAsm (http://www.terraspace.co.uk/uasm.html#p2).
There are other options? I need only MASM
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:15:31 AM
Quote from: Vortex on July 14, 2021, 02:13:45 AM
Hi Timo,

Here is another example :

include     \masm32\include\masm32rt.inc

.data

var         dd  100
string      db 'var = %u',13,10,0

.code

start:

    invoke  crt_printf,ADDR string,var

    invoke  ExitProcess,0

END start

I need only MASM/WinAPI functions, no C
Title: Re: Variable output
Post by: jj2007 on July 14, 2021, 04:21:03 AM
Quote from: Timofeyka on July 14, 2021, 04:13:39 AM
Quote
Use UAsm (http://www.terraspace.co.uk/uasm.html#p2).
There are other options? I need only MASM

Actually, the code that I posted above, and that you claim to have used, assembles fine with MASM. Save your source code, then assemble it, zip both the source and the exe and post it here.
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:23:48 AM
Quote from: jj2007 on July 14, 2021, 04:21:03 AM
Quote from: Timofeyka on July 14, 2021, 04:13:39 AMUse UAsm (http://www.terraspace.co.uk/uasm.html#p2).
There are other options? I need only MASM

Actually, the code that I posted above, and that you claim to have used, assembles fine with MASM. Save your source code, then assemble it, zip both the source and the exe and post it here.
[/quote]
Title: Re: Variable output
Post by: jj2007 on July 14, 2021, 04:25:45 AM
  .data
    sd db "SS",0


So you did not use the code I posted. Please don't waste members' time with such games.
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:29:53 AM
Quote from: jj2007 on July 14, 2021, 04:25:45 AM
  .data
    sd db "SS",0


So you did not use the code I posted. Please don't waste members' time with such games.
Sorry, I thought it wouldn't affect the code, thanks everyone for the answers
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:32:46 AM
Quote from: jj2007 on July 14, 2021, 04:25:45 AM
  .data
    sd db "SS",0


So you did not use the code I posted. Please don't waste members' time with such games.
Sorry, but it only displays a numerical value
Title: Re: Variable output
Post by: jj2007 on July 14, 2021, 04:33:36 AM
Quote from: Timofeyka on July 14, 2021, 04:29:53 AM
Quote from: jj2007 on July 14, 2021, 04:25:45 AM
  .data
    sd db "SS",0


So you did not use the code I posted. Please don't waste members' time with such games.
Sorry, I thought it wouldn't affect the code, thanks everyone for the answers

Every single character affects the code. There is a huge difference between
myvar dd 12345 ; my code: a numeric DWORD variable, ok for str$()
sd db "SS",0 ; a string variable, nonsense for str$()
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:35:05 AM
Quote from: jj2007 on July 14, 2021, 04:33:36 AM
Quote from: Timofeyka on July 14, 2021, 04:29:53 AM
Quote from: jj2007 on July 14, 2021, 04:25:45 AM
  .data
    sd db "SS",0


So you did not use the code I posted. Please don't waste members' time with such games.
Sorry, I thought it wouldn't affect the code, thanks everyone for the answers
Every single character affects the code. There is a huge difference between
myvar dd 12345 ; my code: a DWORD variable, ok for str$()
sd db "SS",0 ; a string variable, nonsense for str$()

I tried to make a variable with
myvar dd "Hi",0
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:37:44 AM
Quote from: Timofeyka on July 14, 2021, 04:35:05 AM
Quote from: jj2007 on July 14, 2021, 04:33:36 AM
Quote from: Timofeyka on July 14, 2021, 04:29:53 AM
Quote from: jj2007 on July 14, 2021, 04:25:45 AM
  .data
    sd db "SS",0


So you did not use the code I posted. Please don't waste members' time with such games.
Sorry, I thought it wouldn't affect the code, thanks everyone for the answers
Every single character affects the code. There is a huge difference between
myvar dd 12345 ; my code: a DWORD variable, ok for str$()
sd db "SS",0 ; a string variable, nonsense for str$()

I tried to make a variable with
myvar dd "Hi",0
If I don't use str$ is don't output anything
Title: Re: Variable output
Post by: jj2007 on July 14, 2021, 04:39:38 AM
Quote from: Timofeyka on July 14, 2021, 04:35:05 AMI tried to make a variable with
myvar dd "Hi",0

Great. Trial and error is what you need as a programmer. Did you succeed? If yes, do you understand why it prints 18537? What about reading a book about numbers and all that stuff?
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:43:05 AM
Quote from: jj2007 on July 14, 2021, 04:39:38 AM
Quote from: Timofeyka on July 14, 2021, 04:35:05 AMI tried to make a variable with
myvar dd "Hi",0

Great. Trial and error is what you need as a programmer. Did you succeed? If yes, do you understand why it prints 18537? What about reading a book about numbers and all that stuff?
Sorry, I just work with assembler only to create a mini-OS for i386, but I'm not very familiar with newer processors, and I can ask stupid questions
Title: Re: Variable output
Post by: jj2007 on July 14, 2021, 04:45:23 AM
Quote from: Timofeyka on July 14, 2021, 04:43:05 AMI just work with assembler only to create a mini-OS for i386

You made my day :mrgreen:
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:46:38 AM
Quote from: jj2007 on July 14, 2021, 04:45:23 AM
Quote from: Timofeyka on July 14, 2021, 04:43:05 AMI just work with assembler only to create a mini-OS for i386

You made my day :mrgreen:
str $ is only intended for converting to a string, but without it nothing is output - at the same time, Uasm / JWasm and C functions do not suit me, is there any other option?
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 04:53:51 AM
Quote from: Timofeyka on July 14, 2021, 04:46:38 AM
Quote from: jj2007 on July 14, 2021, 04:45:23 AM
Quote from: Timofeyka on July 14, 2021, 04:43:05 AMI just work with assembler only to create a mini-OS for i386

You made my day :mrgreen:
str $ is only intended for converting to a string, but without it nothing is output - at the same time, Uasm / JWasm and C functions do not suit me, is there any other option?
I used kip irvines library before, but I need to have access to both print and WriteString, and they conflict
Title: Re: Variable output
Post by: Timofeyka on July 14, 2021, 05:44:54 AM
Quote from: jj2007 on July 14, 2021, 04:45:23 AM
Quote from: Timofeyka on July 14, 2021, 04:43:05 AMI just work with assembler only to create a mini-OS for i386

You made my day :mrgreen:
As strange as it may sound, thank you for not answering) They made me read the MASM32 documentation, and it said that you need to specify the string address! :greenclp:
Title: Re: Variable output
Post by: jj2007 on July 14, 2021, 05:49:04 AM
RTFM is an essential rule for becoming a successful programmer :thumbsup: