Hi I am in a assembly course this semester and I just begun reading the book, I am required to do a program that calculates the following expression: A = (B) + (C-D), using registers here is what I got:
include c:\masm32\include\Irvine32.inc
includelib c:\masm32\lib\irvine32.lib
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\user32.lib
.data
A DWORD 150
B DWORD 100
F DWORD 50
D DWORD 40
.code
main PROC
mov eax,A
mov ebx,B
mov ecx,F
mov edx,D
add eax,ebx
add ecx,edx
sub eax,ecx
mov A,eax
exit
main ENDP
END main
but when I compile it? I think it goes thorugh but then I get this:
/z2
"first.obj"
"first.exe"
NUL
LINK : warning LNK4044: unrecognized option "z2"; ignored
first.obj : warning LNK4033: converting object format from OMF to COFF
first.exe : fatal error LNK1136: invalid or corrupt file
I got expirience with c++ but I am new with assembly so would appreciate some advice and also if anyone knows about a good "tutorial" or lessons wold be good
Thanks!
Welcome,
Masm32 is all you need. The examples in the package are very instructive. Also, search what you need here in the Campus.
There´s a lot you can learn by doing this.
BTW, you know you don´t need Irvine´s includes for what you are doing right? If in the masm32 environment, just include include "\masm32\include\masm32rt.inc" and you will be fine.
I´m building your example without a problem
LordAdef is right. Here is your example in Masm32 version (installation hints (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm)):
include \masm32\include\masm32rt.inc
.data
A DWORD 150
B DWORD 100
F DWORD 50
D DWORD 40
.code
main PROC
mov eax,A
mov ebx,B
mov ecx,F
mov edx,D
add eax,ebx
add ecx,edx
sub eax,ecx
mov A,eax
inkey str$(A), " is the result" ; a Masm32 macro
exit
main ENDP
END main
Output: 160 is the result
There are very good reasons to dump the Irvine library: outdated, not ABI-compliant, etc etc; problem is that apparently many assembler teachers have no idea what they are talking about. If your prof is a reasonable person, try to convince him to look at the Masm32 SDK.
Quoteproblem is that apparently many assembler teachers have no idea what they are talking about
I don´t understand them either... laziness? You could "even" keep Irvine´s book for starter/reference but use masm32 as the working environment. Only god knows...
Quote from: LordAdef on February 26, 2018, 08:36:32 AMlaziness?
Most probably they are proficient in several popular languages like Java, C, Python, but they suddenly find out that they are obliged to teach assembly. So they find the Irvine book in the university library and hack together some exercises. Look at the example above: single letter variables A, B,
CF, D - really, really old members here may remember Dartmouth BASIC 8)
But it works to a certain degree - why drive a Ferrari (Masm32) if you can ride a bicycle (Irvine)? ;)
Hi thank you for the replies!, but I am still unable to get the code going I am using qeditor that comes with masm should I use a different one? the problems that I have are when I compile anything I get the following error:
Using codepage 1252 as default
Creating rsrc.RES
RC: RCPP -CP 1252 -f C:\WINDOWS\system32\RCa06116 -g C:\WINDOWS\system32\RDa06116 -DRC_INVOKED -D_WIN32 -pc\:/ -E -I. -I .
RC : fatal error RC1110 : could not open rsrc.rc
I dont know what to do there and if I build it i get:
LINK : fatal error LNK1181: cannot open input file "C:\masm32\bin\first.obj"
_
Link error
linking it doest help either. I am sorry if Im asking basic stuff but this is the first program that I am creating on assembly language
With qeditor, Project/Console build all 32 should be OK for your project. The rc stuff is a bit mysterious, though. Is your *.asm file in the folder C:\Masm32\ ?
And don't be shy to ask basic stuff. Something in your setup is not "basic", personally I have never seen a commandline that contained C:\WINDOWS\system32\RDa06116, so I really wonder where that crept in...
I have the asm file here: C:\masm32\bin\first.asm
OK, move it to C:\Masm32\first.asm and open it in qEditor.exe. When you click menu Project/Console build all, what do you see? Which error messages if any?
Assembling: C:\masm32\first.asm
***********
ASCII build
***********
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
Volume in drive C has no label.
Volume Serial Number is C4C7-D18C
Directory of C:\masm32
02/25/2018 04:18 PM 323 first.asm
02/25/2018 04:20 PM 2,560 first.exe
02/25/2018 04:20 PM 937 first.obj
3 File(s) 3,820 bytes
0 Dir(s) 31,231,934,464 bytes free
Press any key to continue . . .
No errors whatsoever, I can do almost everything except compile it and when I click run nothing happens, thanks for sticking up with me!
ratten,
Try JJ´s code first!
Your code doesn´t have any output to console, so you will never see anything
oh with JJ's code it promps me the following when I build it:
***********
ASCII build
***********
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
LINK : fatal error LNK1104: cannot open file "first.exe"
_
Link error
and if I try to run it, the program kinda frezzes, and it still gives me the same error when I tried to compile it
So, it builds fine here with qEditor:
Quoteinclude \masm32\include\masm32rt.inc
.data
A DWORD 150
B DWORD 100
F DWORD 50
D DWORD 40
.code
main PROC
mov eax,A
mov ebx,B
mov ecx,F
mov edx,D
add eax,ebx
add ecx,edx
sub eax,ecx
mov A,eax
inkey str$(A), " is the result" ; a Masm32 macro
exit
main endp
end main
Are you saving your file as "whatever.asm" with asm at the end?
Where is your masm32 installed?
QuoteLook at the example above: single letter variables A, B, CF, D - really, really old members here
O noticed that too! Not too asm like
Quote from: ratten on February 26, 2018, 09:34:26 AMLINK : fatal error LNK1104: cannot open file "first.exe"
"cannot open" typically means that the file is in use. If you can see the process in Task Manager, kill it and assemble again.
Note it must be Project/
Console assemble & link, otherwise it assembles as a Windows GUI application, and you can't see any output, plus the inkey won't work.
If it builds successfully, click Project/Run program.
when I click assembly/link it goes through but then I click run and the qeditor goes to not responding and the .exe is still in the background but not showing up then I click build and gives me the link error I just installed it in my laptop and it is doing the same thing.
and also I am on windows 10, I dont know if that has anything to do with it
It works fine for me, see attachment.
- open in qEditor
- menu Project/CONSOLE build all
- menu Project/run program
I am on Win7-64, but I'll test it on Win10, too.
Check your task manager and see if your exe is running in tjee background and that's why qeditor cannot open the exe
THANK YOU SO MUCH! it finally work out for me I restarted my computer and it finally did it!, also I tried to download the file it chrome wouldnt let me, but thanks anyway both helped me a lot! and my professor is not the best one out there to say the least(really old guy), so I tried to read the class book (Assembly Language for x86 Processors (7th Edition) by K. R. Irvine) but it hasnt helped me a lot so I was looking to learn by my self where are the tutorials on the masm32 files?
Try \Masm32\tutorial\console\ and \Masm32\help\
There are also many small demos in \Masm32\examples
thank you, now that I can run it I am trying to improve what the program displays but is given me some strange errors I dont know if you can help me but I kinda want to print each of the the results and diis play the numbers like after adding eax and ebx show the number that eax is holding thisis what I tried but is displaying large extrange numbers:
add eax,ebx
mov A,eax
print str$(A)
mov eax,A
add ecx,edx
mov F,ecx
print str$(F)
mov ecx,F
First, read the Tips, Tricks and Traps part here (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm).
Second, I will not touch or look at any code that does not have all headers and stops at "end start". It must be ready for copy & paste.
This is why the MASM32 SDK is full compliant with the specification of both Intel and Microsoft with what is called the Intel ABI.
add eax,ebx
mov A,eax
print str$(A)
mov eax,A
add ecx,edx
mov F,ecx
print str$(F)
mov ecx,F
The "print" macro calls Windows functions that will overwrite the EAX ECX and EDX registers and the EBX register has a special purpose in the OS so it needs to be protected.
You will not be able to mix Irvine code and MASM32 code for reasons JJ has already explained, the Irvine book is designed to get a student through a semester where the MASM32 SDK is designed for production quality code which must work safely in a Win32 environment.
Here is a simple example of using ADD and SUB in 32 bit MASM.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
comment * -----------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
----------------------------------------------------- *
.code
start:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
call main
inkey
exit
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
main proc
push ebx
push esi
push edi
mov ebx, 4
mov esi, 8
mov edi, 10
mov eax, ebx
add eax, esi
sub eax, edi
add eax, eax
print str$(eax),13,10
print "---------------------------",13,10
mov ebx, 4
print str$(ebx),13,10
add ebx, esi
print str$(ebx),13,10
sub ebx, edi
print str$(ebx),13,10
add ebx, ebx
print str$(ebx),13,10
pop edi
pop esi
pop ebx
ret
main endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end start
Nice! Ratten, you should also use comments in some parts. For example:
Quote from: hutch-- on February 26, 2018, 12:58:37 PM
mov ebx, 4 ; Size of foo...
mov esi, 8 ; 8 times loop...
mov edi, 10 ; Imagine something else...
:biggrin:
Quote from: jj2007 on February 26, 2018, 08:44:24 AM
Quote from: LordAdef on February 26, 2018, 08:36:32 AMlaziness?
Most probably they are proficient in several popular languages like Java, C, Python, but they suddenly find out that they are obliged to teach assembly. So they find the Irvine book in the university library and hack together some exercises. Look at the example above: single letter variables A, B, CF, D - really, really old members here may remember Dartmouth BASIC 8)
But it works to a certain degree - why drive a Ferrari (Masm32) if you can ride a bicycle (Irvine)? ;)
well it was worse many years they still wanted students to drive an old T-Ford(16bitdos), even when windows 32bit existed many years, I guess windows10 not supporting 16bit mode,forced them to quit with16bit programming
I prefer Randall Hyde's book for the assembler bit and ichelions tutorials for get started with masm32 windows api programming
http://www.plantation-productions.com/Webster/ (http://www.plantation-productions.com/Webster/)
why do they not use his book, he has been assembly language teacher,LISA assembler he wrote among things
hope he is still alive and well, do you know anything about that Hutch?
The problem with Randy Hyde's work is it is an old architecture from the DOS era where the assumptions of a segmented architecture are of negative value to anyone wanting to learn modern protected mode programming where FLAT memory model architecture is the only way to design code. The book by Daniel Kusswurm is a modern well designed work that is worth the effort to learn.
Kip Irvine's book is for another purpose, to get undergraduate students through a semester, it is not designed to produce production code for viable applications. The MASM32 SDK was designed from scratch to produce production code that is fully complaint with the 32 bit Intel ABI. It is a bit more difficult to start with but if a leaner is not misled by nonsense and learns to ABI, instruction sets and general coding techniques, they will produce reliable code that runs on all 32 and 64 bit versions of Windows.
Hi I am trying to do another program in assembly and my professor gave me a program that uses 32 bit variables and want us to make the same program using 64 bit variables, and I can't make it work here is the original program with 32 bit variables:
include \masm32\include\masm32rt.inc
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
firstval DWORD 20002000h
secondval DWORD 11111111h
thirdval DWORD 22222222h
sum DWORD 0
.code
main PROC
mov eax,firstval
add eax,secondval
add eax,thirdval
mov sum,eax
inkey str$(sum), " is the result in decimal"
exit
main ENDP
END main
And here is the program that I made:
include \masm32\include\masm32rt.inc
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:QWORD
.data
firstval QWORD 1111000000001100h
secondval QWORD 2222111100000011h
thirdval QWORD 3333222200001111h
sum QWORD 0
.code
main PROC
mov rax,firstval
add rax,secondval
add rax,thirdval
mov sum,rax
inkey str$(sum), " is the result in decimal"
exit
main ENDP
END main
I just changed the register eax for rax because thats what I found for 64 bit registers, and also change the DWORD declarations for QWORD the first program functions just fine but the second one just wont work, hope someone can help me out, Thanks!
If its 64 bit MASM you are looking for, look at the subforum for 64 bit MASM, the modified code will not work as the architecture is different.
Oh Thanks! I just downloaded it and trying to use it should I create a new topic in the 64 bit section? Because I am having some issues
Quote from: ratten on March 11, 2018, 12:32:25 PM
Oh Thanks! I just downloaded it and trying to use it should I create a new topic in the 64 bit section? Because I am having some issues
as an alternative there are movq,paddq MMX/SSE2 integer qword in masm32
you just use XMM0-XMM7 regs instead
although I dont know if printout is supported for 64bit integers in masm32
http://www.felixcloutier.com/x86/PADDB:PADDW:PADDD:PADDQ.html (http://www.felixcloutier.com/x86/PADDB:PADDW:PADDD:PADDQ.html)