News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

x86 Assembler on windows...how to start?

Started by falcon01, July 28, 2011, 03:32:03 PM

Previous topic - Next topic

falcon01

Thanks a bunch, these char routines are just what I wanted!Only problem is that echo is disabled..but I'll combine it with a print char function (whose name is..?XD), no problem.

And if I make a 100byte buffer I discovered I can handle strings too because the stdout->stdin->stdout->stdin sequence works...maybe it was the 1 byte allocation error's doing.
Thanks to everybody now I feel I can at least START making some assembly programs in 32 bit!:D

Mind if I ask some last questions about x86 architecture and instructions in general?
1)What's the difference betweeen lea, offset and address?They do the same thing to me...
2)Is there a way to refer to upper 16 bits of extended registers?Like AX for lower 16 bits.
3)I heard that, respect 8086, they improved the MUL operation...now it should work like this: MUL AX,BX (AX=AX*BX),true?
4)Both addresses and data are 32-bit long and x86 is basically CISC right?So there are instruction which take more space than others.

FORTRANS

Hi,

   1)  LEA is an opcode or instruction.  It is executed by the
processor.  OFFSET or address are assembler directives.
They are evaluated by the assembler, not the processor.

   2)  No, not directly.  you can move the contents of a
32-bit register like EAX to access the upper 16 bits directly.
Look at the instructions BSWAP or the rotate instructions
ROL and ROR.

   3)  That might be the IMUL instruction you are thinking
about.  IMUL got extended versions 8086 => 80386.
MUL BX does something like AX:DX = AX * BX.

   4)  Yes, insructions can range from one byte to around
15 bytes long.  The shortest perform fixed operations.
longer instructions include immediate data and instruction
prefixes such as REP, LOCK, and segment overrides for
instance.

HTH,

Steve N.

dedndave

as to the 1-byte buffer...
you should always allocate 1 byte more than needed   :P
the StdIn routine needs a place for a terminator
if you tell it you have 1 byte, it is full when you start

besides the instructions Steve mentioned, i have had occassion to use another method to access the upper 16 bits
if i want to zero extend or sign extend the upper 16 bits of a register, without destroying the original contents.....
        push    eax
        movzx   edx,word ptr [esp+2]
        pop     eax

        push    eax
        movsx   edx,word ptr [esp+2]
        pop     eax

it may not be particularly fast, but neither is BSWAP   :bg
these code sequences do not alter any flags - also handy
if you do this....
        mov     edx,eax
        shr     edx,16

the flags are altered, and the result is always zero extended


dedndave

i have wanted something like this for a while
so, i took a break from my other project and wrote this routine

you can filter numerics only, alpha only, no spaces, and combinations
i use crt__kbhit and crt__getch
in the spirit of fun, i use WriteFile in the routine instead of the print macro   :P
i do use the macros in the test code, though.....
Console Input Test: sdfsdfSDFDF,....   234242

     Length EAX: 25
Buffer Size ECX: 255
   Buffer [EDX]: sdfsdfSDFDF,....   234242

Spaces Allowed:
      No Filtering: sdfsdfsdSDFD.....   234
      Numeric Only:    345345345  353534
        Alpha Only: sfsdfsdf   sdfsdfSDFS sdf
Alpha-Numeric Only: sdfsddSDFD34234   234234

Spaces Not Allowed:
         No Spaces: sdfsdf3242423....
      Numeric Only: 34234234
        Alpha Only: sdfdfsdSDFSD
Alpha-Numeric Only: dfsdfsd234234SDFSDF3234


this one supports backspace
but it does not allow line editing like arrow keys or insert mode/overwrite
it does allow tab, but i will also make backtab work and add the line editing stuff later

FORTRANS

Hi,

   An addendum to Dave's code in reply #32.


        MOV     EDX,EAX ; Make working copy..
        SAR     EDX,16  ; Move high word to low word,
                        ; sign extended, flags affected.


   The PUSH/access/POP stuff was new to me at least, thanks.

Cheers,

Steve N.

dedndave

ah yes - should have thought of that, Steve   :U