Jump to content
  • Advertisement
Sign in to follow this  
sdlprorammer

Assemly help

This topic is 5170 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi have a problem. I can't find any tutorials to learn x86 Assembly for windows. I found this code:
; First assembly program. This program asks for two integers as
3 ; input and prints out their sum.
4 ;
5 ; To create executable using djgpp:
6 ; nasm -f coff first.asm
7 ; gcc -o first first.o driver.c asm_io.o
8
9 %include "asm_io.inc"
10 ;
11 ; initialized data is put in the .data segment
12 ;
13 segment .data
14 ;
15 ; These labels refer to strings used for output
16 ;
17 prompt1 db "Enter a number: ", 0 ; don’t forget null terminator
18 prompt2 db "Enter another number: ", 0
19 outmsg1 db "You entered ", 0
20 outmsg2 db " and ", 0
21 outmsg3 db ", the sum of these is ", 0
22
23 ;
24 ; uninitialized data is put in the .bss segment
25 ;
26 segment .bss
27 ;
28 ; These labels refer to double words used to store the inputs
29 ;
30 input1 resd 1
31 input2 resd 1
32
33 ;
34 ; code is put in the .text segment
20 CHAPTER 1. INTRODUCTION
35 ;
36 segment .text
37 global _asm_main
38 _asm_main:
39 enter 0,0 ; setup routine
40 pusha
41
42 mov eax, prompt1 ; print out prompt
43 call print_string
44
45 call read_int ; read integer
46 mov [input1], eax ; store into input1
47
48 mov eax, prompt2 ; print out prompt
49 call print_string
50
51 call read_int ; read integer
52 mov [input2], eax ; store into input2
53
54 mov eax, [input1] ; eax = dword at input1
55 add eax, [input2] ; eax += dword at input2
56 mov ebx, eax ; ebx = eax
57
58 dump_regs 1 ; print out register values
59 dump_mem 2, outmsg1, 1 ; print out memory
60 ;
61 ; next print out result message as series of steps
62 ;
63 mov eax, outmsg1
64 call print_string ; print out first message
65 mov eax, [input1]
66 call print_int ; print out input1
67 mov eax, outmsg2
68 call print_string ; print out second message
69 mov eax, [input2]
70 call print_int ; print out input2
71 mov eax, outmsg3
72 call print_string ; print out third message
73 mov eax, ebx
74 call print_int ; print out sum (ebx)
75 call print_nl ; print new-line
76
1.4. CREATING A PROGRAM 21
77 popa
78 mov eax, 0 ; return back to C
79 leave
80 ret


But it is so different form this one: And why doesn't it start wiht ".386"??
.386 
.model flat,stdcall 
option casemap:none 
include \masm32\include\windows.inc 
include \masm32\include\kernel32.inc 
includelib \masm32\lib\kernel32.lib 
include \masm32\include\user32.inc 
includelib \masm32\lib\user32.lib 

.data 
MsgBoxCaption  db "Iczelion Tutorial No.2",0 
MsgBoxText       db "Win32 Assembly is Great!",0 

.code 
start: 
invoke MessageBox, NULL, addr MsgBoxText, addr MsgBoxCaption, MB_OK 
invoke ExitProcess, NULL 
end start 

The problem is that i can't fimd one version of Assembly and start learning! I want to learn how to loop in Assembly, how to select, how to make arrays, functions etc. and then go to deeper waters, if there are any. Isn't there any tutorial for this kind of Assembly? Which one of the 2 codes is better, and why are they different? and by the way i prefer console..

Share this post


Link to post
Share on other sites
Advertisement
The second one looks like no assembler I've ever seen - I know zilch about x86, but do know some z80. The second one appears to use macros; in the way that you do this in Z80:


ld a,3
ld (curcol),a
ld a,5
ld (currow),a
ld hl,text_string
bcall(_puts)
text_string:
.db "HELLO!",0


to display some text, but could "macrofy" it to do this:


; Stick the following in an external file to #include:
#define print_string(x,y,text) ld a,x \ ld (curcol),a \ ld a,y \ ld (currow),a \ ld hl,text \ bcall(_puts)

; This line would be in your "actual" source file.
print_string(3,5,text_string)

text_string:
.db "HELLO!",0


I hope that makes sense - the second one is like your second source file in that the actual assembler code has been turned into a macro, which can be less efficient.
It's a lot easier, of course... but you will gain more from using the first method.

Share this post


Link to post
Share on other sites
Quote:
Original post by sdlprorammer
why doesn't it start wiht ".386"??
Different syntax. The first one is for the NASM assembler, the second one is for MASM.

Quote:
Original post by sdlprorammer
Isn't there any tutorial for this kind of Assembly?
[google] ...ok, I'll throw in a search term as well: "Art of Assembly"

Quote:
Original post by sdlprorammer
Which one of the 2 codes is better, and why are they different?
They do completely different things... the first looks like it adds and prints out two numbers and dumps the registers and memory. The second one displays a message box titled "Iczelion Tutorial No.2" with the text "Win32 Assembly is Great!" and an "OK" button.

Share this post


Link to post
Share on other sites
i already found some tutorials but they are all different.

>Different syntax. The first one is for the NASM assembler, the second one is for MASM.

I want to learn Assembly. I want to learn standard assembly, without any implementation dependencies like those 2 codes, that will compile in all the compilers for windows. What will i do?

Share this post


Link to post
Share on other sites
There is no single standard for assembly syntax on x86, most of the variations are fairly similar in most respects though. If you want portable use a high level language - one of the design goals of C was for it to be a 'portable assembler'.

Share this post


Link to post
Share on other sites
Buy Assembly Language Step by Step: http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=175q24u9EP&isbn=0471375233&itm=3

Jeff Dunteman is the man!

Share this post


Link to post
Share on other sites
There are a whole bunch of variations of assembler, here's a few compilers:
MASM32
NASM
A86

The examples you gave were from NASM and MASM32. The NASM example will output in DOS. MASM32 will give you a messagebox in Win32. MASM is macro based, but if don't want to use the macros you can still us the lower level version.

Here's some tutorials that can get ya started (Sorry for not linking them, in a hurry):
http://k2pts.home.comcast.net/gbaguy/x86asm.htm
http://www.drpaulcarter.com/pcasm/index.php
http://win32asm.cjb.net/
http://webster.cs.ucr.edu/ (More a bridge between Assembly and other High level languages)

Share this post


Link to post
Share on other sites
:'( NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO! no no no.

Can i use MASM32 for console programming? I don't want to make windows, just console prgramming. Also, low level activities such as opening ports, prinitng etc. are supported from all those compilers?

And finally, if you want to learn Assembly what do you do? Do you have to learn all those variations? Also, the book Art of Assembly, what assembler and variation does it use? Pls give some general things that you think i might want to know, although i read some stuff, it seems that what i read was not what i wanted to learn.. You are the experiecned..

Share this post


Link to post
Share on other sites
Yes you can use MASM for console programming in windows.

The Iczelion tutorials are a good start. The Windows API is not just for windowed programs. They can be used in console mode programs also.

Look for linkers settings /SUBSYSTEM:CONSOLE to build a console application. Use /SUBSYSTEM:WINDOWS to build a windows application.

Share this post


Link to post
Share on other sites
Thanks but the The Iczelion tutorials are not a good start. They teach how to build windows style programs, and they don't teach you Assembly - loops, ifs, structures, functions etc. Well they might teach you but i don't want to learn a bunch of useless stuff ( windows style programs ) before i learn how to use Assembly for Console. Where can i find this thing i am looking for? Assembly Language for console.

Also, low level activities such as opening ports, prinitng etc. are supported from all those compilers?

Also, the book Art of Assembly, what assembler and variation does it use?
thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!