News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Print

Started by somecoder, June 06, 2009, 01:10:24 AM

Previous topic - Next topic

somecoder

Hi,

I have searched online and can't seem to find any information for the print function in masm. Would anyone be kind enough to explain what the numbers represent i.e 10, 13?


dedndave

13,10
you have em backwards
they are carriage return and line feed
if you look at most text, including this text, there is a CR/LF pair at the end of each line
you do not see them, but you see the result
carriage return resets the x position to 0
line feed increments the y position
when you hit the enter key, it generates a carriage return character, and the line feed is added to it by software

the masm32 library has a print macro
if you prefer to do it without using the macro, you can use one of a few different API functions
i prefer to use the GetStdHandle function to get the standard output handle
then use the WriteFile function to put characters on the screen

somecoder

Cool...

Maybe you can help... I am having some problems echoing out some of the varibles inside the struct... it echos out symbols and I need it to echo out as integar but I can't find any documentation that outlines the various methods I can use with print :(


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
    option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\wsock32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\winmm.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\wsock32.lib
includelib \masm32\lib\kernel32.lib

include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib
include \masm32\macros\macros.asm

   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

.data
;wsaData - Struct for WSAStartup
wVersion WORD ?         
wHighVersion WORD ?
szDescription BYTE 257 DUP(?)
szSystemStatus BYTE 129 DUP(?)
iMaxSockets WORD ?
iMaxUdpDg WORD ?
lpVendorInfo DWORD ?


.code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc
    invoke WSAStartup,0101h,ADDR wVersion
   
    'print hex$( ADDR wVersion),13
    ;print ADDR szDescription,13,10,13,10
   
    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start

dedndave

yes - that is a good one - lol
it would take hours upon hours to fully document all the macros
i learned to use the print macro, primarily by reading example code
here are a few examples

print edi       ;prints the zero-terminated string at the address pointed to by edi register
print str$(edi)  ;prints the value in edi in decimal
print chr$(13,10)  ;prints the ascii carriage return and line feed
print chr$("Some text",13,10)  ;prints "Some text", followed by carriage return/line feed

honestly, i do not know how to use the macro fully - but these will get you started

jj2007

#4
Quote from: somecoder on June 06, 2009, 01:32:32 AM
Cool...

Maybe you can help... I am having some problems echoing out some of the varibles inside the struct... it echos out symbols and I need it to echo out as integar but I can't find any documentation that outlines the various methods I can use with print :(


include \masm32\include\masm32rt.inc
uselib wsock32 ; this lib not included in masm32rt
   
.data?
wsaData WSADATA <?> ; initialise empty structure

; wVersion WORD ?         
; wHighVersion WORD ?
; szDescription BYTE 257 DUP(?)
; szSystemStatus BYTE 129 DUP(?)
; iMaxSockets WORD ?
; iMaxUdpDg WORD ?
; lpVendorInfo DWORD ?

.code

start:
    mov esi, offset wsaData ; load pointer to structure
    invoke WSAStartup, 0101h, esi ; get values
    movzx eax, [esi.WSADATA.wVersion] ; version is a WORD, so you need movzx
    print hex$(eax), 13, 10 ; print it
    lea eax, [esi.WSADATA.szDescription] ; load effective address of the string
    print eax ; print it
 
    inkey chr$(13, 10, 10, "-- OK --")
    exit

end start


cobold

somecoder,

Quote from: somecoder on June 06, 2009, 01:32:32 AM


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc

comment ********                            You don't need
option casemap:none                         any of these, because
include \masm32\include\windows.inc         all of them are defined
include \masm32\include\user32.inc          in masm32rt.inc already
include \masm32\include\wsock32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\winmm.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\wsock32.lib
includelib \masm32\lib\kernel32.lib

include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib
include \masm32\macros\macros.asm

comment ********

end start


and....
Quote from: somecoder on June 06, 2009, 01:32:32 AM
I have searched online and can't seem to find any information for the print function in masm

Open the marcros.asm file in your masm directory with your prefered editor and search for "print MACRO". Ah let's se what it does....

   print MACRO arg1:REQ,varname:VARARG      ;; display zero terminated string
       invoke StdOut,reparg(arg1)
     IFNB <varname>
       invoke StdOut,chr$(varname)
     ENDIF
   ENDM


you see that the print macro uses StdOut. As StOut is "invoked" it is defined as a PROC in the masm library:
C:\masm32\m32lib\stdout.asm:
; #########################################################################

   .386
   .model flat, stdcall
   option casemap :none   ; case sensitive

   include \masm32\include\windows.inc
   include \masm32\include\kernel32.inc

   StrLen PROTO :DWORD

   .code

; #########################################################################

StdOut proc lpszText:DWORD

   LOCAL hOutPut  :DWORD
   LOCAL bWritten :DWORD
   LOCAL sl       :DWORD

   invoke GetStdHandle,STD_OUTPUT_HANDLE
   mov hOutPut, eax

   invoke StrLen,lpszText
   mov sl, eax

   invoke WriteFile,hOutPut,lpszText,sl,ADDR bWritten,NULL

   mov eax, bWritten
   ret

StdOut endp

; #########################################################################

end


So, this is a simple method to find out how the macros work.



hutch--

 :bg

Quote
it would take hours upon hours to fully document all the macros i learned to use the print macro, primarily by reading example code here are a few examples

As a matter of fact it DID, many of them. A voice crying in the wilderness, RTFM. I went slowly blind and mad writing all of this documentation for the MASM32 macros, plonked them on the editor menu so it could easily be found and at least some people still don't use the reference material.

I might add I absolutely HATE writing documentation but if you don't, not many can use the capacity.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

Hutch, are you refering to "MASMREF.DOC" ?
i hafta get a program to open it with

MichaelW

The file is \masm32\help\hlhelp.chm.
eschew obfuscation

cobold

hutch,

Quote from: hutch-- on June 06, 2009, 07:50:28 AM
I might add I absolutely HATE writing documentation but if you don't, not many can use the capacity.

I think this thread is a good occasion to tell you: Thanks for writing all the documentation, even if you hate doing that!

I didn't want to undermine this work of yours, I just wanted to show somecoder that one can track exactly what a macro does and learn a lot from it.

nice weekend to all

cobold

dedndave

yes Hutch - excellent
and, realizing how much time you and a few others have put into it,
you should know that you guys have easily saved 1,000 times that in man-hours for others   :U  :U
it will be even better, now that I know which doc to look at   :lol  (thanks Michael)

hutch--

cobold,

No problems, I thought your explanation was clear and very useful.

Dave,

Complete with sad violins  :boohoo: the voice crying in the wilderness keeps coming back to me, from the earliest version of MASM32 many used to ignore the reference material and help files then either ask questions why they didn't exist or even funnier, whine at you over the algo and macro design. Now if there was a way to send an electric shock through the mouse buttons if they had never used the help menu I would even have a go at it. I remember writing into one of the early installers "Psssst, this is a secret, read the help file" but it did not seem to sink in.

I wonder if its worth a try to use subliminal mesaging, flash "READ THE HELP FILES" for about one 20th of a second every 5 seconds or so until the user sinks the idea in subliminally and selects the help menu.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

well - what got me was the name "hlhelp.chm"
i wasn't really thinking of macros as being "high-level"
typically, i looked in "masm32.chm" and "masmlib.chm"
if i didn't find what i wanted there, i would first look at the macro itself and get what i could out of that
then, i would go looking at examples
live and learn - lol
not that the approach i have been using is bad - i have learned a lot that way

Mark Jones

The help files are quite essential. Of course, the MASM32 package is not, and never was, designed as a beginner's package ("beginner's assembler" is an oxymoron in and of itself), so it is quite nice to have any documentation at all. Thanks Hutch. :bg

Several years ago I developed an electronics project using a PIC 16F877 microcontroller. As a beginner, I found a great GoogleGroup for a simple ALGOL-style compiler language called JAL (short for "Just Another Language".) Because JAL was so simple, it attracted many people who assumed they could learn microcontroller engineering in one afternoon. Needless to say, there were thousands of "RTFM!!" comments (RTFD!! actually, as it was the Datasheet which needed memorized, there was no manual.) So critical was memorizing the datasheet, that the standard noobie response was along the lines of "You must be willing to live, eat, and sleep the Datasheet." A blanket "Welcome to JAL" response was born, which said that if the newcomer could not memorize the 400-page+ datasheet, then there was literally zero chance of success. After developing a few projects (and referencing the datasheet probably three thousand times in the process), I quickly learned this was true.

Moral of the story: All help files ... were produced for a reason. They should always be referenced when questions arise. The newcomer is doing themselves a disservice if they do not reference them first. :wink
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

dedndave

i remember pic 16xxx's - i used to work for GI
they made a few video game chips and calculators as well - lol (tank was one)
some fun stuff, although i am not a big fan of anything to do with a clean room