News:

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

Main Menu

really basic assembler syntax

Started by gelatine1, December 09, 2013, 08:21:21 AM

Previous topic - Next topic

gelatine1

Hello,
I am new to this forum. I have some experience with the assembly language. I used to program it for my calculator (16bit though). I thought to try something different now and I found this site and compiler and stuff.
But it was quite dissapointing for me because it looks like it is not even made of assembler syntax. There are alot of instructions like all those includes and then the 'invoke ...'. There are even if statements...
So now my question was if I could also work with this without all those kind of things? And how then? (maybe a quick example?) The only thing I would like to keep is something to output the value of my registers or something.

If you have any questions with my question feel free to ask,
Thanks in advance

Jannes

dedndave

the .if statements and INVOKE are not a requirement
they do, however, save you a lot of typing
the assembler turns them into "real" code

for any INVOKE, the assembler pushes parameters, then calls the function
        INVOKE  MessageBox,HWND_DESKTOP,offset szMessage,offset szTitle,MB_OK
        push    MB_OK
        push    offset szTitle
        push    offset szMessage
        push    HWND_DESKTOP
        call    MessageBox


you will soon learn that INVOKE saves typing and make it a little easier to read the code

dedndave

not so much for .if/.else structures in code - lol
i personally prefer the old ways, but it makes it easier for beginners who are coming from C
    .repeat
        ;do stuff
        dec     ecx
    .until ZERO?


loop00:
; do stuff
        dec     ecx
        jnz     loop00


the assembler generates more-or-less the same code for both

KeepingRealBusy

Jannes,

let me try to make some sense out of your question.

Your second sentence "I have some experience with the assembly language.". In your third sentence you say you are working with a calculator. It has internal registers. Some of them may be directly addressable but they are relatively addressable. You enter values with the keypad and using special keys you construct expressions separated with operators and you get a result displayed.

All this can be done with assembly language in the PC. Depending on whether you are assembling in 64 bit mode or 32 bit mode, the internal registers are 64 or 32 bits wide. You have roughly 16 registers available in 64 bit mode, and 7 registers available in 32 bit mode. These registers can be loaded with input values or calculated values, and then saved or further processed by operations, or the saved values can be loaded back into the registers for further calculations.

With the calculator, you are usually using registers which can calculate or display floating point numbers (3.14159 etc.) There are also two different sets of floating point registers in the PC, a set of 8 in the Floating Point Unit (FPU) that are 64 bits wide, and a set of 8 registers in the SSE (128 bits wide). These can all be accessed using assembly language.

The assembler is not a compiler. It can do things that resemble what a compiler can do using macros. It assembles the input source lines of a program and creates machine instructions that can execute in one specific processor type. It creates an executable program that can be loaded into a PC and executed. When the program is entered, it has nothing other than what it was assembled and linked with (libraries of pre-assembled instructions), other than possible command line parameters entered when the program was started.

The process of entering a value in a register can be accomplished in several ways, such as reading a console input directly, or by displaying a Message Box and requesting that the user enter a value.

A register can also be loaded with pre-computed values that the assembler will kindly evaluate for you . These values are saved a binary values in several different sizes such as BYTES, WORDS, DWORDS, QWORDS, or DQWORDS (1 BYTE, 2 BYTES, 4 BYTES, 8 BYTES, or 16 BYTES).

Memory locations can also be used to hold message strings that can be output directly to the console or output via Message Boxes.

Registers, once loaded with values, can be added, subtracted, multiplied, divided, anded, ored, or exclusive ored with other registers or memory locations.

The computer is a wonderful tool, and has so much more to offer beyond just numeric manipulations using a calculator. In fact, the computer has a built in calculator that is much more powerful than your 16 bit version.

Any questions? Have I explained more than you really wanted to know?

Dave.

hutch--

Hi Jannes,

The problem most have when they come to 32 and 64 bit assembler code in Windows is that of working in a protected mode operating system where the only way to handle file IO, display and a massive range of other capacities is through the operating system. This leaves you with two types of code, high to very high level OS functions and true low level algorithms.

While the OS code can be complex and messy to deal with, it is basically "hack" code to do simple things like create a window, buttons and similar controls, read and write from storage devices and so on. The real action is in algorithm design and here you will find a mountain of true low level assembler code.

MichaelW

Code that is easier to type and read is generally less likely to contain errors. Keeping track of complex logic in assembly code implemented the "old way" can be difficult, for me at times requiring comments that express the logic in what is effectively a high-level syntax. It would be more efficient to code the logic in high-level syntax and leave off the comments.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

in the original scenerios, i try to take advantage of all 4 methods

INVOKE is generally the best, but there are times when PUSH/CALL works to an advantage

the same holds true for if/endif vs labeled branches
i use the if/endif when it works best
but, some loop structures are difficult to write that way

gelatine1

#7
Hi, thank you all for your replies. but I have a few more things to say. feel free to leave any more comments.

Dave,
Thanks for your long explanation. Some of the things you said I already knew because my calculator is not just like a normal one. it's a graphical one whereto I can upload hexadecimal files made from assembly language. It uses a few different things like the 'mov' instruction is the same as the 'ld' instruction for my calculator.
I even wrote my own floats for it. (only addition and subtraction though)

Hutch,
So you mean that it is actually possible to create some kind of window function (Like CreateWindowEx) but that it is just really hard to write?
Or did you mean exactly the opposite that it is not possible because it is protected?

MichaelW,
I am not programming to create something great, or to have something rather easy. If I would want that I'd simply go back to C++.
I have a competition coming up in 2.5 months and it will be important to write programs as efficient and as less memory using as possible. This should be a great way to learn it and I just like this language :)

dedndave,
I'd rather don't use all those predefined functions and stuff. Otherwise I could accept the invoke as a useful 'cheat'.

Jannes

jj2007

Quote from: gelatine1 on December 09, 2013, 11:43:39 PMI'd rather don't use all those predefined functions and stuff. Otherwise I could accept the invoke as a useful 'cheat'.

Hutch maintains a special demo for Real MenTM at \Masm32\examples\exampl07\slickhuh\slickhuh.asm ;)

dedndave

there are advantages to all those methods
i like to use the one that best applies for the current situation

one advantage of using if/else/endif is, you don't have to make up (or type) label names   :biggrin:
that can speed up the code-writing process, in many cases

also - it's good to understand them all
when you read someone else's code, it won't seem like a foriegn language