News:

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

Assembler language Idiot

Started by sSword, May 11, 2006, 09:35:52 PM

Previous topic - Next topic

sSword

Hi
Im new to Assembler language and am finding it real difficult to get started

I have read numerous tutorials and dont seem to be able to understand them :(

All I need todo is take a decimal number from a keyboard input and output its binary and octal equivilent on the screen

I would like to make an executable file eventually but its not important to do that now.

The thing is I dont even know where to begin....

Any help or n00b links would be v cool

many thanks




Ar-ras

Assembler isn't hard...
Maybe you are such a noob that doesn't know anything about windows, cpu and IO
If so, read first how these things work !

If you never programmed, then have a lot of fun  :bdg

dsouza123

Below is a list of number conversion functions from the masm32 library.
Most notably atodw, dw2bin_ex in your case.

There is also the windows function wsprintf which can convert a number
to a string in different number bases. Format specifer %o to convert to octal.

Functions in the masm32.lib
; --------------------------
; numeric and text conversions
; ----------------------------
a2dw   PROTO :DWORD
atodw  PROTO :DWORD          ; return value in eax
htodw  PROTO :DWORD          ; return value in eax
dwtoa  PROTO :DWORD,:DWORD   ; value - buffer
dw2a   PROTO :DWORD,:DWORD
dw2hex PROTO :DWORD,:DWORD

 ; ------------------------------
 ; extended performance functions
 ; ------------------------------
   atodw_ex      PROTO :DWORD
   byt2bin_ex    PROTO :BYTE,:DWORD
   wrd2bin_ex    PROTO :WORD,:DWORD
   dw2bin_ex     PROTO :DWORD,:DWORD
   bin2byte_ex   PROTO :DWORD
   dw2hex_ex     PROTO :DWORD,:DWORD
   hexflip32     PROTO :DWORD

 ; -----------------------------------
 ; high speed binary / hex conversions
 ; -----------------------------------
   bin2hex       PROTO :DWORD,:DWORD,:DWORD
   hex2bin       PROTO :DWORD,:DWORD

dsouza123

atodw takes a decimal string (a string made of numbers from base 10  all individual numeric characters from the list  0123456789)
    and converts it to a dword (a 32 bit integer value that is stored in memory or a register)

dw2bin_ex takes a dword and creates a string in base 2 ( a binary number as a string using only numeric chararcters of 01)

wsprintf using the format specifer %o takes a dword and converts it to an octal string ( base 8 number as string using 01234567)

ChrisLeslie

Hi sSword

The following code will take an input from the keyboard and display it as binary and hex. It is rather high level and spread out for clarity and uses the procedures from the masm32 library rather than starting from scratch. By this means you can easily see the overall structure of a 32 bit masm assembly source. Then, by looking into the library procedures you can see the detail of the code for each procedure. Perhaps as an excercise you could try expanding my version with the actual code in the procedures and create a lower level version .
.386
.model flat,stdcall
option casemap:none
      include \masm32\include\windows.inc
      include \masm32\include\masm32.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      includelib \masm32\lib\masm32.lib
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
      include \masm32\macros\macros.asm
           
.data
    msg1 db 40 dup(0)
    myNumber dd ?
    crlf db 13,10
    asDecimal db 40 dup (0)
    asBinary db 40 dup(0)
    asHex db 40 dup(0)
.code

main proc
    invoke StdIn,ADDR msg1,LENGTHOF msg1
    invoke atol,ADDR msg1
    mov myNumber,eax
   
    invoke dw2bin_ex,myNumber,ADDR asBinary ; display as binary string
    invoke StdOut,ADDR asBinary
    invoke StdOut,ADDR crlf

    invoke dw2hex_ex,myNumber,ADDR asHex ; display as hex string
    invoke StdOut,ADDR asHex
    invoke StdOut,ADDR crlf
 
    invoke ExitProcess,0
main endp 
     
end main


Regards

Chris

RedXVII

If youre serious about learning assembly, my advice to you is to get a debugger (like Olly) and step through/glance over the program (tutorial of some sort) youve compiled. You see it how it actually works and its much easier to grasp assembly.

Good luck  :U

skywalker

Quote from: ChrisLeslie on May 12, 2006, 12:07:38 PM
Hi sSword

The following code will take an input from the keyboard and display it as binary and hex. It is rather high level and spread out for clarity and uses the procedures from the masm32 library rather than starting from scratch. By this

Chris,

This is what is output with 123 as the input.

00000000000000000000000000000000
00000000

ChrisLeslie

skywalker

QuoteChris,

This is what is output with 123 as the input.

00000000000000000000000000000000
00000000
Thanks for trying my example.
If I input 123 I get:
00000000000000000000000001111011
0000007B

... both on my home and work computers. Someone may have an explanation?

Regards

Chris

dsouza123

With 123 for input I get

00000000000000000000000001111011
0000007B

for output.

PBrennick

skywalker,
You are obviously doing something wrong here.

Chris,
Always be careful about what people say to you as critique (as you have done), because they can accidently lead you astray.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

skywalker

Quote from: PBrennick on May 13, 2006, 05:01:56 PM
skywalker,
You are obviously doing something wrong here.

Paul


I am assembling code as given and no errors are given.
I can attach my .exe if that'll help.

Andy




Ra man

Here is a problem:
QuoteCODE SECTION
START:
RET
Save this file in the prog folder calling it, say, Nothing.asm

GoAsm Nothing
GoLink Nothing.obj /console
Save this file in the prog folder calling it gonothing.bat
done this.
QuoteGo to the "start" menu, programs, and click on "MS-DOS prompt"
Type "gonothing" and press enter.
I even tryed c:\prog\gonothing.bat
C:\Documents and Settings\Owner>c:\WindProgr\gonothing.bat

QuoteC:\Documents and Settings\Owner>GoAsm Nothing
'GoAsm' is not recognized as an internal or external command,
operable program or batch file.
that's the answer.
I v XP home.
How to get it work?

IAO

Hi to all:
I write bad the English.  If I make an error. Excuses me.

Mr. Ra man:
I think that its problem must consult it in sub forum of goasm.  Moderate by Mr. Donkey.
http://www.masmforum.com/simple/index.php?board=8.0
I do not want to offend. I think that some moderator will clear your post.

Regards
bye('_').
"There is no way to peace. Peace is the way."    Mahatma Gandhi

MichaelW

Ra man,

The problem appears to be that your command prompt is opening in C:\Documents and Settings\Owner, and Windows cannot find GoAsm starting from that location. I think you can correct the problem by specifying the full path to GoAsm in the batch file. Instead of running the batch file from a command prompt you can just run it directly, but you will need to add a pause command to the end of the batch file to keep the command window from closing immediately.

eschew obfuscation

PBrennick

skywalker,
Attached is Chris' project assembled using masm32.  The entire project is included, test it, it works.

Paul

[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website