GIDForums  

Go Back   GIDForums > Computer Programming Forums > Assembly Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #11  
Old 12-Dec-2008, 00:19
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Assembly Tutorial?


At least it did something... How about 'as' ,, do you have as?
Not sure what your code was, post it next time. (and use the c++ code enclosure icon)
A C++ program is done like this in g++:
CPP / C++ / C Code:
#include <iostream>
using namespace std;

int main()
{
  int i = 3;
  cout << "Enter a number: ";
  cin >> i;
  return i;
}
/*
I save above as '081211_test.cpp'

I compile like this:
g++ -Wall -W -pedantic 081211_test.cpp -o 081211_test

The I run like this:
./081211_test
Enter a number: 4   <-- there is my input

Then I view the return value like this:
echo $?             <-- the command 
4                   <-- the output
*/
  #12  
Old 12-Dec-2008, 02:27
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


First of all thank you so much. you got the sense of teaching not like others so it is impressive.(knowing that will not be paid for just like lunix ...lol) but really thanks and what goes arround comes arround also that programming ground pdf book is looking very sharp at least till chap 3 which i am still reading ( i wanted to remind you that i am talking data structure I using c++) so the reason i am trying to run a cpp application is to see how the lunix will display the "hello assembly " string to the screen, therefore my program is
CPP / C++ / C Code:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;// i will use that integer i to make the compiler wait for i
cout<<"Hello Assembly"<<endl;
cin>>i; // usually i use Ctrl+F5 to see the output in the windows console
// as i am new to lunix i wanted to see how it works.
return 0;
}
so i will check the as -v. to see if it integrated with g++.
thank you again.
  #13  
Old 12-Dec-2008, 08:24
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


Hi again i also run the as-v and i think it seems ok this is what i got
heikel@heikel-desktop:~$ as -v
GNU assembler version 2.18.93 (i486-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.18.93.20081009.

Also i wish if u tell me how to get a assembly hello word we will call the file : test.s and i wanna run in in this compiler. So i can see the result.
thanks forward
  #14  
Old 12-Dec-2008, 10:22
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Assembly Tutorial?


Looks like your off and running! Very good.
I'm not clear about what you want to do with your C++ hello program and assembly.
I haven't learned how to work assemby into C or C++ yet.... but I guess it's on the 'to learn' list...

I would suggest that you play through the first 3 examples in 'Programming From the Ground UP',
the 'exit' , 'maximum value' , and 'function' examples, and createl your own Hello in assembly alone.
When I say 'play' I mean: compile, link, run, observe neat stuff, make experimental changes, repeat

In the 'maximum value' example you can see how an array of 'long's (4 bytes) is created.
( there is your data structure) Also note how it is manipulated by indexing like in C an C++.
He also shows you the datatypes including the '.ascii' type.
And you should have noticed how int 0x80 calls are how you 'do stuff'

So you set stuff up - and do it ,,,, set stuff up - do it....
There is a linux sys opcode reference at the bottom of this linux/nasm tutorial:
cin.ufpe.br/~if817/arquivos/asmtut/index.html
There you can find the 'write' opcode with which you can print the ascii array (string) to the screen
It shows what values to put in what registers to make the 'syscall'.
You can look these functions up in section 2 of the man pages.
eg: man 2 write (you'll want to do this... (ain't linux cool))

So basically all you need to do is:
-define an .ascii array (much the same as the 'long' array is defined in 'maximum' example)
-load up the registers with the proper values to make the 'write' syscall (look up, observe, think, try)
-make the call (int 0x80)
-exit (as shown in 'exit' example)

See what you can do with what you learned from the book!
Next you will want to learn about using gdb (debugger)!
  #15  
Old 12-Dec-2008, 11:14
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


Hi, the more i read your replies the more i believe you are a teacher, or at least you got the teacher way.
so i did run my c++ test using this command to compile it g++ -test.cpp -o test
so it did generate a file called a.out and test(exe) and i fdid find out that to run the application i should type this: ./a.out and the program did run. so by analogy if i write my assembly hello World i should compile it using this command : as -test.s -o test
and run it : ./a.out
  #16  
Old 12-Dec-2008, 11:50
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Assembly Tutorial?


Very similar... just Do the Examples in the Book First!
At the top of the exit example he shows you EXACTLY how to compile the as assembler code.
Just Do it!

What editor are you using. I use vim.
I generally open two xterms side by side. iuse the command
mkdir project1 ... to make a new directory called project1 for this particular project then I change directory with:
cd project ...in each xterm so both are in the same place. Then in the right xtem I open vim like this:
vim ...To open vim with no filename loaded or
vim myproject.cpp ... to open the editor with a existing file loaded (or a new blank file with that name) or
vimtutor ...to quickly learn how to use vim
I type 'i' (insert mode) to begin adding text and 'ESC' to stop that mode and save with ':w' or quit with ':q',
get help with ':help' . It is different at first but very powerful.
Then on the left xterm I do all compiling and running.
So I can switch back and forth between xterms with 'alt>tab' and edit/try/edit /try...etc
If I need I open another xterm. Right now I have five xterms and this browser open in this virtual window. (and I need them alll!)
Seriously, do the excercises , at least through 'maximum value'...
  #17  
Old 12-Dec-2008, 12:10
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


As of now i was still in the begining of chap 3 by tonight i may go through it all now my question is if u can tell me where to download the vim editor i am using the text editor of lunix also if u can tell me how to make a directory called Assembly into my documents without using the GUI interface and can you tell me what this mean in lunix shell terminal
heikel@heikel-desktop:~$
~$ : ??
thanks.
  #18  
Old 12-Dec-2008, 12:38
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Assembly Tutorial?


Good take your time in chapter 3. Do not proceed unless you understand. If you don't understadnd , ask.
Everybody's got vim!!! (or should) did you try: (you should know this drill by now)
man vim
whereis vim

Make a directory... you know how to open an xterm right?
Well when you open an xterm you should be in yur home directory that is:
/home/yourusername
If you type:
ls -l

you will see a listing of unhidden files and directories. If you type:
mkdir mynewdir

and do ls -l again you will see your new directory listed. If you type:
cd mynewdir

You will be in the new directory,,,,
man ls , man mkdir , look at bottom of any man page for a list other related man and info pages to check out for 'more info/
There is a lot of great linux stuff (beginner on up) here: http://tldp.org/
I gotta go
  #19  
Old 12-Dec-2008, 21:08
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Assembly Tutorial?


Quote:
can you tell me what this mean in lunix shell terminal
heikel@heikel-desktop:~$
It is your shell prompt. It is customizable. Looks like Ubuntu makes yours:
username@machine_name-present_working_directory-$:
the '-$: ' just marks the end of it. Does it change if you change directory (cd)?
If you do a 'pwd' (present working directory) what do you get? '/home/heikel/desktop' ?
There is this for the prompt (and much more): tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html
  #20  
Old 13-Dec-2008, 01:50
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


Hi, after my last post i went to copy that code for the program to dispaly the 0 with the command ech$?
now i did read the max program i am trying to comment that with c++ analogy i hope i won't mess up a lot
CPP / C++ / C Code:
.section .data
data_items:
.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0
" the data_items is a tag name for the long array
the long array is initialized to size 13 (items) and 
the last 0 will indicate that there is 
no more items in the array long type"
.section .text "??"
.global _start "??"
_start: " it is like int main() in c++;"
movl $0, %edi " we are assigning the value 0 to register edi."
movl data_items(,%edi,4), %eax " here we are asigning
the value of the first item in the array type 
(long, i think the size is 4 byte) which index 0 to register eax"
movl %eax, %ebx " like saying %ebx=%eax."
start_loop: "??"
cmpl $0, %eax " it is like a condition to return true, false
if(0==%eax) else the compiler skips the next line"
je loop-exit " tag to the code that ends the application"
incl %edi " like c++ : edi++"
mov data_items(,%edi,4), %eax " loading the next
item in the list i hope u can go over this part 
i do understand what it is doing but the syntax part 
i wanna know more about it"
cmpl %ebx, %eax " if %ebx>%eax skip a line 
and read after it else go back to the loop 
so we will retreive the next item. 
i wish if u go over the cmpl instruction cuz 
the book says it compare two integer and discard t
he result but returns a flag ??"
"now the last part is to call interruption 80 to exit the application. i also want to know hoe echo$? will dispaly the %ebax which is holding the max value in the array"
i hope i did get something if your next posting will clarify more those points i should be able to modify the same code to return the Min value in the .long array
i will get back to read the rest of the chapter.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mixing C and assembly in x86 - Makefile nuances aijazbaig1 Assembly Language 3 23-Apr-2008 09:29
Tutorial: How to Make a Web 2.0-Style Logo PhotoshopTrend Graphics Forum 0 20-Sep-2007 06:57
Assemblers & assembly language BlueFireCO. Assembly Language 2 26-Mar-2007 10:56
Photoshop Tutorial: Make An Inspirational/Mystical Picture ToddSAFM Graphics Forum 9 09-Aug-2005 21:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:28.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.