![]() |
|
#41
|
|||
|
|||
Re: Assembly Tutorial?While you are able to see an 'A' printed to the screen from you .int 65 I don't think you understand what is really going on.
Do you know what the value of 'hello_len' was in the above? Do you realize you were attempting to 'write' that many characters to the screen? (and not 1) 'A' was the only one to show because it was 'printable'. The others were all zero's... leal places an address in the second operand and movl places the value stored at that address in the second operand. I covered leal as best I could in post #33... read through that slowly and experiment. Have you been able to run the above through gdb? You really need to do that to learn what is going on. Do you realize that you will NOT be able to print the integer 1975 ? It will have to be converted into ascii bytes: 0x31 , 0x39 , 0x37 , 0x35 To write a program to do this automaticlly will be quite involved. (and btw, I graduated High School in '73, darn...) Last edited by Howard_L : 31-Dec-2008 at 01:07.
|
|||
|
#42
|
|||
|
|||
Re: Assembly Tutorial?Happy New Year
1 - you graduated high school in 73 and i am born in 75 cool that makes me feel more secure about my ignorance (i really feel bad because it is like i am starnded in the quick sand i lift a leg up to loose the other one lol) but i won't give up. 2 -my gdb is like the new born baby in the house it is rocking my as compiler and what was missing is these steps: i did not have the nop instruction. i did not know that we have to run the app and then step into the code. 3 - My first question is about ur last post u said i don't quite get what is going on, well i hate to admit but it not very clear so here my first foggy area. hello: # this is a tag the memory given to this var by the compiler will hold the value (true / false) hello_len: .long . -hello (only god and u knows what this is really ? and that does not include me at least for now) CPP / C++ / C Code:
Well i have to wish u a good year. |
|
#43
|
|||
|
|||
Re: Assembly Tutorial?Ok ready?
Quote:
It is not easy to examine values during runtime like we can using printf() etc. in C or C++. With GDB we can see anything we want at any point during code execution! We set a 'breakpoint' with the gdb directive 'break' or just 'b' in order to stop the program at a point so that we can observe it's state at that time. Once we are stopped at the breakpoint we can then 'step' through each program instruction. The break must be set inside the running portion of the code (the .text portion). You can use symbols or line numbers to break on. If you try to break on _start the program will not stop at all. If you try to break on the line following _start gdb will not show the first instruction. The reason for using the combination of 'nop' in the code and 'break *_start+1' in gdb is so that gdb will not skip the first instruction. (well actually it does, 'nop' is the first instruction and it is skipped) Quote:
Alright, I'll try to explain what I think I might know. It is a symbol that has address associated with it in the symbol table which represents a location in the code which is the first byte of the memory where that data will be stored. The size of this memory area will vary depending on what you declare. How about something to play with which will answer many questions: CPP / C++ / C Code:
Code:
I note that: - Output has no spaces or new line because none were given to be print! We would need an 0x20 for a space or an 0x0a for a newline. - The first write (of the 4 .int bytes of hello) printed 1 strange character. That is what is printed in place of SOME non-printable characters. Others will have no output at all. (I'll explain more about this further down) - The next two 'writes' printed the digits as we were hoping. Ok so got all that? Code:
Use gdb to answer ALL your questions... Happy New Year to you All too. Last edited by Howard_L : 31-Dec-2008 at 17:52.
|
|
#44
|
|||
|
|||
Re: Assembly Tutorial?Hi, I guess u knew that question was coming so i hope u follow what i did(btw i wanted to tell you i am familiar with dec,hex,binary connversion)
i took these three value 3,34,19756 and i watched how the bytes are written in the RAM so this is the original code CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
the 22h is the value of 34 in hexa stored in byte 1(reversed) 4 will be the size 4byte=32 bits so really my hello should be the first half only "0x22 0x00 0x00 0x00" or hello will be 64 bits ? correct i hope if it is true what are this part then "0x04 0x00 0x00 0x00" 0x80490c4 <hello>: 0x22 0x00 0x00 0x00 0x04 0x00 0x00 0x00 0x80490c8 <hello_len>:0x04 0x00 0x00 0x00 0x33 0x34 0x02 0x00 now if we look at the hello_len the first 32 bits it is the last 32 bits of hello"0x04 0x00 0x00 0x00" and here where i really need ur explanation although 34 is stored as an integer we see the hex ascii code for 34 (0x33,0x34) and then there is 2 which is probably how many bytes are written for 34 so i will stop here for now then after this answer i will ask more if i need too i feel we getting some where right now so the data structure part may be is related to how the byte are written into memory Thanks Again |
|
#45
|
|||
|
|||
Re: Assembly Tutorial?Good to see you are playing around!
Yes 34 decimal is 22 hex: Code:
|
|
#46
|
|||
|
|||
Re: Assembly Tutorial?happy new year well i guess u can tell my party is with bytes and ascii sorry about the long posting but check this the shortest version should have been this :
0x80490c4 <hello>: 0x22 0x00 0x00 0x00 0x04 0x00 0x00 0x00 0x80490c8 <hello_len>:0x04 0x00 0x00 0x00 0x33 0x34 0x02 0x00 if hello hold the data (22h=34 ) i color coded the part that need ur touch (hahaha) 1-what is hello_len holds ? if hello will hold the value wich is 22h or 34 decimal 2-how do u explain that i see the ascii code of my decimal 34 0x33,0x34 in the red colored part for hello_len 3-why the length of hello and hello_len is 64 bits not 32bits 4-what is the 0x02 after the 0x33 0x34 0x02 0x00 now if step in hello2 and hello2_len this what we will have: 0x80490cc<hello2>: 0x33 0x34 0x02 0x00 0x00 0x00 0x33 0x34 0x80490ce<hello2_len>:0x02 0x00 0x00 0x00 0x33 0x34 0x02 0x00 5- why there is a repetition of 0x33 0x34 in the blue part of hello2 6 -why the 2nd part of hello2_len is the first part of hello2 i hope my 6 question are clear and i hope the color coded part will help.... Happy new year to all |
|
#47
|
|||
|
|||
Re: Assembly Tutorial?What is actual 'x'amine line that produced the above?
As I said above , it looks like you are showing 8 bytes and not 4. int's on my machine are 4 bytes. The output you show looks like yours are a 4 byte size too. On 64 bit machines an int may be 8 bytes. What 'hello_len' value does the program return for you? It is ESSENTIAL that you provide the EXACT data declarations , 'x'amine directives, output, etc. in order for us to accurately address your issues. eg: Code:
People can do EXACTLY what I have done and note their results. Note that using 'code' or 'C/C++'tags preserves the spaces in your output and code. Regular html will only show a maximum of one space between words etc. I think if you take your time and use careful observation you can answer most if not all of your above questions. Quote:
Last edited by Howard_L : 01-Jan-2009 at 13:58.
|
|
#48
|
|||
|
|||
Re: Assembly Tutorial?do not laugh but i wanted to delete the last two posts because as soon as i get home i said why am i asking very stupid questions why ?? to be honest with u, iam still looking for a good excuse to come up with but i don't have any yet (so u may wanna provide one for me so i won't look that dump)
CPP / C++ / C Code:
i wanna step into hello and hello2 and look at the 4 bytes occupied by hello and hello2 which is the following CPP / C++ / C Code:
cout<<34(decimal for sure) ? i know in c++ we use the static_cast<type1>(type2) and it will convert type2 to type 1 1 - how we do that in assembly ? 3 - i am not familiar with all the data types that assembly will support like decimal for example ( all i know so far is what u taught me, so if u can list a couple with their default size in bytes) i am looking more for about the conversion or let's say how the static_cast works from the inside, till i hear from u thanks. |
|
#49
|
|||
|
|||
Re: Assembly Tutorial?Code:
|
|
#50
|
|||
|
|||
Re: Assembly Tutorial?Hi howard, trust me i have tried hardly to wait 24 hours but when i got home i couldn't sleep till i came up with this code i know this is not the best way to code it but i took me like 4 hours to write it, it did work i am not sure if it is coded right
CPP / C++ / C Code:
|
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
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