hey,
As a first simple project I'm trying to create a calculator with + and - operators(maybe * and / will add later), so I and to masm32 editor click on Code tab and then "Create New Console Application" this was the result:
; ₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪
include \masm32\include\masm32rt.inc
; ₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪
comment * -----------------------------------------------------
Build this console app with
"MAKEIT.BAT" on the PROJECT menu.
----------------------------------------------------- *
.data?
value dd ?
.data
item dd 0
.code
start:
; ₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪
call main
inkey
exit
; ₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪
main proc
cls
print "Hello World",13,10
ret
main endp
; ₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪₪
end start
- include \masm32\include\masm32rt.inc - how can I know which functions are in this file?
- what's .data? (with question-mark at the end) ? why we need it? etc..
- inkey and exit are built-in MASM functions or MASM32 functions? how can I know? how(if possible..) can I see the source?
- what's "cls" and "ret"? MASM keywords? MASM32 functions? what they do?
That's all for now :)
Thanks every body!
Michael
include \masm32\include\masm32rt.inc - how can I know which functions are in this file?
By reading it. Notepad is your friend.
what's .data? (with question-mark at the end) ? why we need it? etc..
Uninitialised global data, set to zero by the OS. Does not bloat the executable.
inkey and exit are built-in MASM functions or MASM32 functions? how can I know? how(if possible..) can I see the source?
what's "cls" and "ret"? MASM keywords? MASM32 functions? what they do?
They are Masm32 macros, see \masm32\macros\macros.asm
In contrast, functions are either on MSDN (Windows API) or in \Masm32\m32lib
See also Help and tutorials (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm).
Michael,
You need to start looking around the MASM32 SDK, there is a directory that has the MASM32 library and there is a directory that has the main macro file but the easiest way is to look at the help files in the menu of the MASM32 editor.
The notation ".data?" indicates uninitialised data where the ".data" is data that has pre-defined content link string data. The first ".data?" is used to allocate space to write global variables and it has the advantage of not increasing your executable file size where ".data" is where you put data that has a value as well as pre-defined content.
The reason why the MASM32 SDK has both libraries and macros is because MASM does not have any runtime library at all. Even a C compiler has a basic runtime library. Without this combination it is extremely difficult for a new user to understand what is happening or to write successful code as writing a runtime library is an advanced task.
Thanks guys, didn't see the help folder...
This is a very interesting topic, because console input/output in today's Windows running in protected mode is not trivial, at least in a sense. Part of the reason for console i/o seeming to be a challenge is that how to do it is not documented well, at least if a beginner does not know where to look. As has been pointed out, if MASM32 is installed, then looking at the example and demo code in the directories under the MASM32 main directory is a good start. However, there is a problem: these methods differ little from those of Kip R. Irvine or Sivarama P. Dandamudi (both of whom have written excellent books on assembly language!) and others, in that the implementation details are still hidden by macros and libraries. Now, using macros and libraries is a good thing, not a bad thing, so please don't misunderstand me here.
What I would find extremely helpful is an example of putting characters on the console text screen and getting characters from the console keyboard, all using the absolute minimum number of include files and libraries. Perhaps something like textio.asm in the c:\masm32\examples\exampl02\textio.asm, but without the macro examples. In looking at the information on MSDN for the ReadConsole function, we would need kernel32.lib (and its inc file?) and perhaps the assembly language equivalent of Windows.h.
One final question - using higher level language libraries and Windows APIs is going to require certain registers to contain certain values. Where might this information be available?
Thank you for any information on this, and also thank you for this site!!!
~todd
Todd,
> One final question - using higher level language libraries and Windows APIs is going to require certain registers to contain certain values. Where might this information be available?
In 32 bit Windows it is called the Intel "Application Binary Interface" (ABI for short). The quickest way to find it is in the MASM32 help file "ASM Intro Help", "Register Preservation Convention"
on the help menu in the default editor. You will get a more detailed version by finding Agner Fog's tech data but I am sorry, I don't have the link handy.
deleted
There is a distinction that needs to be maintained between Kip Irvine's book and the MASM32 SDK, the former is designed to get students through a semester where MASM32 is designed for reliable production code. Importantly, compliance with the Intel ABI is one of the main differences and if you wish to write reliable useful code, you will ensure that you observe the ABI.
Quote from: todd on January 12, 2017, 03:04:07 AMWhat I would find extremely helpful is an example of putting characters on the console text screen and getting characters from the console keyboard
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
Init
Let esi="programming in assembly"
PrintLine "The string '", esi, "' can be edited; the Escape key clears it"
.While 1
Let esi=Input$(At(5, 5 ) "What's your hobby? ", esi)
.Break .if !Instr_(esi, "assembl", 1) && Len(esi)>3
Print At(5, 8 ) "You are not serious, my friend,.,"
Delay 1000
Print At(5, 8 ) Space$(40)
.Endw
Inkey At(5, 8 ) "Congrats, your hobby is ", esi
EndOfCode
deleted
Quote from: nidud on January 12, 2017, 08:23:39 AM
https://msdn.microsoft.com/en-us/library/078sfkak.aspx
QuoteImportant
This API cannot be used in applications that execute in the Windows Runtime
New feature?
Here are some more that are not supported:
Quote_ismbcalnum _ismbcalnum_l _ismbcalpha _ismbcalpha_l _ismbcdigit _ismbcdigit_l _ismbcgraph _ismbcgraph_l _ismbchira _ismbchira_l _ismbckata _ismbckata_l _ismbcl0 _ismbcl0_l _ismbcl1 _ismbcl1_l _ismbcl2 _ismbcl2_l _ismbclegal _ismbclegal_l _ismbclower _ismbclower_l _ismbcprint _ismbcprint_l _ismbcpunct _ismbcpunct_l _ismbcspace _ismbcspace_l _ismbcsymbol _ismbcsymbol_l _ismbcupper _ismbcupper_l _mbbtombc _mbbtombc_l _mbbtype _mbbtype_l _mbccpy _mbccpy_l _mbccpy_s _mbccpy_s_l _mbcjistojms _mbcjistojms_l _mbcjmstojis _mbcjmstojis_l _mbclen _mbclen_l _mbctohira _mbctohira_l _mbctokata _mbctokata_l _mbctolower _mbctolower_l _mbctombb _mbctombb_l _mbctoupper _mbctoupper_l _mbsbtype _mbsbtype_l _mbscat _mbscat_l _mbscat_s _mbscat_s_l _mbschr _mbschr_l _mbscmp _mbscmp_l _mbscoll _mbscoll_l _mbscpy _mbscpy_l _mbscpy_s _mbscpy_s_l _mbscspn _mbscspn_l _mbsdec _mbsdec_l _mbsicmp _mbsicmp_l _mbsicoll _mbsicoll_l _mbsinc _mbsinc_l _mbslen _mbslen_l _mbslwr _mbslwr_l _mbslwr_s _mbslwr_s_l _mbsnbcat _mbsnbcat_l _mbsnbcat_s _mbsnbcat_s_l _mbsnbcmp _mbsnbcmp_l _mbsnbcnt _mbsnbcnt_l _mbsnbcoll _mbsnbcoll_l _mbsnbcpy _mbsnbcpy_l _mbsnbcpy_s _mbsnbcpy_s_l _mbsnbicmp _mbsnbicmp_l _mbsnbicoll _mbsnbicoll_l _mbsnbset _mbsnbset_l _mbsnbset_s _mbsnbset_s_l _mbsncat _mbsncat_l _mbsncat_s _mbsncat_s_l _mbsnccnt _mbsnccnt_l _mbsncmp _mbsncmp_l _mbsncoll _mbsncoll_l _mbsncpy _mbsncpy_l _mbsncpy_s _mbsncpy_s_l _mbsnextc _mbsnextc_l _mbsnicmp _mbsnicmp_l _mbsnicoll _mbsnicoll_l _mbsninc _mbsninc_l _mbsnlen _mbsnlen_l _mbsnset _mbsnset_l _mbsnset_s _mbsnset_s_l _mbspbrk _mbspbrk_l _mbsrchr _mbsrchr_l _mbsrev _mbsrev_l _mbsset _mbsset_l _mbsset_s _mbsset_s_l _mbsspn _mbsspn_l _mbsspnp _mbsspnp_l _mbsstr _mbsstr_l _mbstok _mbstok_l _mbstok_s _mbstok_s_l _mbsupr _mbsupr_l _mbsupr_s _mbsupr_s_l is_wctype
deleted
Guys,
Can we keep the debate out of here as this was a question from a new member who probably does not need a pile of extraneous information.
A ml64 example :
OPTION DOTNAME
OPTION casemap:none
PUBLIC start
include ConsoleTest.inc
.data
format db 13,10,'Hello %s , nice to meet you.',0
string1 db 'Please type your name :',13,10,0
.data?
hOutput qword ?
hInput qword ?
buffer db 64 dup(?)
buffer2 db 64 dup(?)
.code
start:
sub rsp,4*8+8
mov rcx,STD_OUTPUT_HANDLE
call GetStdHandle
mov hOutput,rax
mov rcx,STD_INPUT_HANDLE
call GetStdHandle
mov hInput,rax
mov rcx,rax
mov rdx,ENABLE_LINE_INPUT or \
ENABLE_ECHO_INPUT or \
ENABLE_PROCESSED_INPUT
call SetConsoleMode
mov rcx,OFFSET string1
call StdOut
mov rcx,OFFSET buffer
mov rdx,64
call StdIn
mov rcx,OFFSET buffer2
mov rdx,OFFSET format
mov r8,OFFSET buffer
call wsprintf
mov rcx,OFFSET buffer2
call StdOut
xor rcx,rcx
call ExitProcess
StdOut PROC lpszText:QWORD
LOCAL bWritten :QWORD
LOCAL sl :QWORD
LOCAL _lpszText:QWORD
sub rsp,5*8+8+8
mov _lpszText,rcx
; rcx -> lpszText
call lstrlen
mov sl,rax
mov rcx,hOutput
mov rdx,_lpszText
mov r8,sl
lea r9,bWritten
mov QWORD PTR [rsp+4*8],0
call WriteFile
mov rax, bWritten
ret
StdOut ENDP
StdIn PROC lpszBuffer:DWORD,bLen:DWORD
LOCAL bRead :QWORD
LOCAL _lpszBuffer:QWORD
sub rsp,5*8+8
mov _lpszBuffer,rcx
; rcx -> lpszBuffer
mov r8,rdx
mov rdx,rcx
mov rcx,hInput
lea r9,bRead
mov QWORD PTR [rsp+4*8],0
call ReadFile
mov rcx,_lpszBuffer
call lstrlen
sub rax,2
mov rcx,_lpszBuffer
mov BYTE PTR [rcx+rax],0
mov rax,bRead
sub rax,2
ret
StdIn endp
END
Thanks to all who replied. I especially appreciate the code sample from Vortex. I also thank Nidud for the example of how to use the C library. And a special thanks to Hutch for his comment on ABI - this was something I had not considered.
At the risk of doing a little hero worship here - the more I prowl around the MASM32 directories and files, and use the MASM32 IDE and this site, I am left with one word - WOW!! I sincerely thank all who have made MASM32.com one of the most valuable assembly language resources on the net. Well done!
~todd