News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Compiler and Question

Started by buck12, December 24, 2013, 04:27:18 AM

Previous topic - Next topic

buck12

Hello,
I am a student at a University and I was wondering if anyone can suggest a good compiler/editor for assembly at home?
Also, we have a book with all the opcodes but does anyone have a link with all the register and opcode information?
Searching electronic files is much better.

I have searched already and found ok information but nothing that has all of it in one file such as pdf for example.

Also, our professor posted a code snipped which he assigned for bonus points on our homework but I cant seem to make heads and tails out of it.
Address Command omments
6CACEAC0 PUSH EBP sample_exe.6CACEAC0
6CACEAC1 MOV EBP,ESP
6CACEAC3 AND ESP,FFFFFFF0 DQWORD (16.-byte) stack alignment
6CACEAC6 PUSH ESI
6CACEAC7 PUSH EDI
6CACEAC8 PUSH EBX
6CACEAC9 SUB ESP,764
6CACEACF MOV [ESP+2C],EDX
6CACEAD3 LEA EBX,[ESP+3C]
6CACEAD7 MOV [ESP+30],EAX ASCII "3146"
6CACEADB MOV ECX,[6CB01D00]
6CACEAE1 XOR ECX,ESP
6CACEAE3 MOV [ESP+75C],ECX
6CACEAEA PUSH 400 /Count = 1024.
6CACEAEF PUSH EBX |Buffer
6CACEAF0 PUSH DWORD PTR [6CB03960] |hModule = 6CA90000 ('sample_exe')
6CACEAF6 CALL [6CAE701C] \KERNEL32.GetModuleFileNameA
6CACEAFC XOR EAX,EAX
6CACEAFE PUSH EAX /hTemplate
6CACEAFF PUSH EAX |Attributes
6CACEB00 PUSH 3 |CreationDistribution = OPEN_EXISTING
6CACEB02 PUSH EAX |pSecurity
6CACEB03 PUSH 1 |ShareMode = FILE_SHARE_READ
6CACEB05 PUSH 80000000 |DesiredAccess = GENERIC_READ
6CACEB0A PUSH EBX |FileName
6CACEB0B CALL [6CAE7020] \KERNEL32.CreateFileA

dedndave

in the upper right corner of the forum page, you will find a MASM32 Downloads link
you can download and install the masm32 package

1) close all other apps before installation
2) install the package in the root folder of the same drive you want to use for project files

look in the masm32 examples and help sub-folders to get going
and - there are hundreds of examples on the forum

dedndave

the code opens the program file in read mode
and - it does it the hard way   :lol:

buck12

Thanks, I downloaded and installed it. Everything went well, lots of testing while its installing.

As for the code, I saw from the bottom that its opening a file in read mode.

I was wondering why are they XOR EAX,EAX?
This makes no sense to me.
Then it pushed EAX twice. Why?
Then pushed 3 into the stack and then EAX again.
Why are the notes different? Am I missing something here?

Gunther

Hi buck12,

first things first: Welcome to the forum.

Quote from: buck12 on December 24, 2013, 05:50:06 AM
I was wondering why are they XOR EAX,EAX?


         xor        eax, eax


The result is: eax contains the value 0.

Gunther
You have to know the facts before you can distort them.

dedndave

sets EAX to 0, 2 bytes of code
    xor     eax,eax

sets EAX to 0, 5 bytes of code
    mov     eax,0

it can also be done with SUB EAX,EAX

the pushed values are parameters for the windows API functions

GetModuleFileName requires 3 parameters

http://msdn.microsoft.com/en-us/library/windows/desktop/ms683197%28v=vs.85%29.aspx

we would normally write it as
    INVOKE  GetModuleFileName,hModule,lpFilename,nSize

the assembler would then generate the code
    push    nSize
    push    lpFilename
    push    hModule
    call    GetModuleFileName


when the call returns, the function removes the parameters from the stack

CreateFile has 7 parameters

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx

buck12

Gunther, thanks for the welcome!  :biggrin:

dedndave, Thanks for the input so far. I think I am on my way. I am kind of confused as to why the professor is giving 86 based assembly examples when we are learning 68HC11 so far.  :biggrin:

The forum looks like its active and I think this will be a great resource to have.

The biggest thing will be to just start coding and see the assembly code afterwords. We always get code to decipher and typically its simple stuff.

PS what is up with the same question verification at the bottom? India, down, 4, communist?

jj2007

Quote from: buck12 on December 24, 2013, 02:21:12 PMI am kind of confused as to why the professor is giving 86 based assembly examples when we are learning 68HC11 so far.  :biggrin:

Buck, you are fine, it's your professor who is confused :P

From my 68k times I can assure you that they are not compatible, neither hardware- nor syntax-wise. But of course, the same concepts apply. The x86 family has no BSR-type conditional call, though :(

Welcome to the Forum :icon14:

dedndave

one of the better instructors, i would say
assembly language isn't about one type or group of processors
although, this forum is dedicated to windows operating systems and intel x86 processors

if you learn a motorola CPU and an intel CPU, you will see that learning others gets easier and easier
as you play with more and more CPU's, adding another one to the list is simple   :biggrin:
it's actually harder to learn a new assembler syntax that to learn a new CPU or microcontroller - lol

i was recently approached to write some Arduino code in ASM
first thing i learned is - the Arduino isn't designed for that
and the second thing - i would probably have to write my own win32 cross-assembler
and, Arduino's use different chips, so it would be a group of assemblers   :(
screw that - give it to a C programmer - lol

buck12

I hear you guys. There are two sides to the story. I do however get the feeling myself that he is seeing who ventures outside the box.

I dont mind since most applicable things can relate to x86 architecture. The 68HC11 is a good starting point I guess to keep things more simple.

I do have a follow question: I see calls to 32bit memory locations which are pretty straight forward. I also see 32 bit calls to say sample_exe.7342BFD4.
I know the internal memory location can change where there application resides but how about the file location?
How can you translate that call into something which is applicable to the file or executable?