Hello,
I want to learn assembler, so I am more interested in doing everything myself. Surely this is possible? What I want to do first is print numbers and string to the screen. So I can see what my newbie programs are doing. So do I have to include all those files and libraries? is the windows.inc necessary?
thanks.
Quote from: plaguez on January 21, 2012, 05:08:07 PMSo do I have to include all those files and libraries? is the windows.inc necessary?
no, but it makes things easier.
Especially as beginner you should use the HLL stuff, which comes with MASM and the MASM32 package (IMO).
plaguez,
Yo can do it that way if you take long enough and know enough about it. First you create your own include files and libraries so that you can interface with the operating system, then you write your own runtime library so you can doo all those hacky things like write to the screen, file IO and so on. Should be about 5 years work from scratch. :P
i think i can understand his point
using things that are pre-made can hide underlying information
for example, if you use the "print" macro, you have no idea what happens and really don't learn anything
may as well be writing in BASIC :P
but, there is a better approach to learning
in the example i mentioned, use the print macro
but, do a little research into how the macro is written
it calls a function - look that function up and understand it
that function uses a few API calls - look them up
then, use the macro to be productive and learn something else
you can write things for windows without using windows.inc
but - you will be learning the same things over and over - and not move very fast, either :'(
i can write a simple trivial without windows.inc, but you don't want to write only trivials
i can't imagine writing anything useful without the inc files
Here's the print macro
print MACRO arg1:REQ,varname:VARARG ;; display zero terminated string
IFNDEF __UNICODE__
invoke StdOut,expand_prefix(reparg(arg1))
ELSE
invoke StdOutW,expand_prefix(reparg(arg1))
ENDIF
IFNB <varname>
IFNDEF __UNICODE__
invoke StdOut,chr$(varname)
ELSE
invoke StdOutW,chr$(varname)
ENDIF
ENDIF
ENDM
It invokes StdOut, which is this
; #########################################################################
.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
Which invokes WriteFile.. That's windows API To be found Here (http://msdn.microsoft.com/en-us/library/aa365747(v=vs.85).aspx)
If you download the MASM32 Installer, and unpacks the .zip, you can then again unpack the .exe witch contains the source for the diffrent macros :)
it also uses GetStdHandle
so, for those API functions, use MSDN...
GetStdHandle
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx
WriteFile
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747%28v=vs.85%29.aspx
at the bottom of those pages is a list of links for further reading
for example, at the bottom of the GetStdHandle page is a link...
Console Handles
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682075%28v=vs.85%29.aspx