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
  #41  
Old 31-Dec-2008, 00:09
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
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?


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  
Old 31-Dec-2008, 02:43
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

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:
 u said that i am trying to print that many char 
(what are these chars and how did i end up with the "A" in my screen)
4 - As i am typing this reply i am reading post 33 i even printed it, so i know that will be more questions about it as i still have to understand the last code u posted the one that helped my gdb to work . so i am just hoping u won't start hitting ur head against the wall because of all these questions.
Well i have to wish u a good year.
  #43  
Old 31-Dec-2008, 17:21
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
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?


Ok ready?
Quote:
i did not get what the break *_start+1 meant really although break is to step into the code, and i did not know that we have to run the app and then stepinto the code.
Well it sounds like your getting somewhere with gdb now. GOOD
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:
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?)
hello: ...is a variable name.... deal with it, that's it , end of story...ha...
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:
.section .data

      hello:  .int 1975                     #an int is 4 bytes
  hello_len:  .int . - hello

     hello2:  .ascii "1975"                 #these are 4 bytes
 hello2_len:  .int . - hello2               #note the order of each in output

     hello3:  .byte 0x31, 0x39, 0x37, 0x35  #these are 4 bytes
 hello3_len:  .int . - hello3               #note the order of each in output

.section .text
.globl _start
_start:
  nop
  xorl %eax, %eax       #use xorl to zero out the register
  movl $4,   %eax       #sysop 4: 'write'
  xorl %ebx, %ebx
  incl %ebx             #make ebx 1 to 'write' to stdout (the screen)
  leal hello,     %ecx  #get address of the block of bytes to write into ecx
  movl hello_len, %edx  #get number of bytes to write into edx
  int $0x80             #gets linux kernel to DO the opcode we put in eax

  xorl %eax, %eax       #print hello2
  movl $4,   %eax
  leal hello2,  %ecx    #ebx will remain 1 from last call, no need to redo
  movl hello2_len, %edx
  int $0x80

  xorl %eax, %eax       #print hello3
  movl $4,   %eax
  leal hello3,  %ecx
  movl hello3_len, %edx
  int $0x80

  xorl %eax, %eax        #exit
  incl %eax              #sysop 1 , exit with return (view with 'echo $?' )
  xorl %ebx, %ebx
  movl hello2_len, %ebx  # stick a return value here in ebx
  int $0x80
/****************************************************
Compiling , linking and running:

as -gstabs zat-1.s  -o zat-1.o
ld zat-1.o  -o zat-1
./zat-1
?19751975
First a straight run without gdb:
Code:
./zat-1 ?19751975

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:
Now a run within gdb: gdb ./zat-1 GDB is free software... blah blah (gdb) (BTW , gdb has pretty good built in help. Just type 'help' for more info. You can add a specific directive you want help with too like: 'help break') Ok so the gdb prompt is there waiting for me to give some directives. I enter these at the beginning of the gdb run. (you can just mouse-copy / paste this kind of stuff into gdb): break *_start+1 run Then I add these directives. They will cause the register values print with each step: display /x $edx display /x $ecx display /x $ebx display /x $eax Ok now do a step ,,, I get this: (gdb) step _start () at zat-1.s:17 17 movl $4, %eax 4: /x $eax = 0x0 3: /x $ebx = 0x0 2: /x $ecx = 0x0 1: /x $edx = 0x0 ----- Ok so we're sitting there just before the first 'movl $4, %eax' is executed and those are the register values. Let's take a look at how how 'hello', hello2, and hello3 are stored: First we need the addresses of all our variable symbols which we can get by using the 'info' directive: (help info) (gdb) info address hello Symbol "hello" is at 0x80490c4 in a file compiled without debugging. (gdb) info address hello_len Symbol "hello_len" is at 0x80490c8 in a file compiled without debugging. (gdb) info address hello2 Symbol "hello2" is at 0x80490cc in a file compiled without debugging. (gdb) info address hello2_len Symbol "hello2_len" is at 0x80490d0 in a file compiled without debugging. (gdb) info address hello3 Symbol "hello3" is at 0x80490d4 in a file compiled without debugging. (gdb) info address hello3_len Symbol "hello3_len" is at 0x80490d8 in a file compiled without debugging. Well now , see how they are all 4 bytes apart? THAT is how the declaration: hello_len: .int . - hello ... is able to work. Do you have info pages in Ubuntu? type: info as ...and the as info pages should come up. Anyhow, my info as pages show that:
Quote:
The special symbol '.' refers to the current address that 'as' is assembling into.
What that means is the dot represents the place in memory that the next thing will go as the code is loaded to run. So, in the above, when we are just about to write the values represented by hello_len we are at 0x80490c8. From right there we can look back at the 'hello' symbol and count the distance (in bytes) between ,, which is 4. Same for the others ,, see? Now moving on, now that we gdb to show us the addresses we can look at what is stored there with the 'x' directive (x for examine). I will use this arrangement: (gdb) x /4xb address Which means xamine that address and show as specified by format directives (/). If no format is specified 'x'amine will initially display 4 bytes in hex OR whatever format was specified in the last use. In this case I have '/4xb' which means: quantitiy to print: 4 , output format: x for hex , size of each: b for bytes Ok so here is what is stored at the 4 bytes at each of those locations: (gdb) x /4xb 0x80490c4 0x80490c4 <hello>: 0xb7 0x07 0x00 0x00 (gdb) x /4xb 0x80490c8 0x80490c8 <hello_len>: 0x04 0x00 0x00 0x00 (gdb) x /4xb 0x80490cc 0x80490cc <hello2>: 0x31 0x39 0x37 0x35 (gdb) x /4xb 0x80490d0 0x80490d0 <hello2_len>: 0x04 0x00 0x00 0x00 (gdb) x /4xb 0x80490d4 0x80490d4 <hello3>: 0x31 0x39 0x37 0x35 (gdb) x /4xb 0x80490d8 0x80490d8 <hello3_len>: 0x04 0x00 0x00 0x00 Or we can look at that whole area like this: (gdb) x /24xb 0x80490c4 0x80490c4 <hello>: 0xb7 0x07 0x00 0x00 0x04 0x00 0x00 0x00 0x80490cc <hello2>: 0x31 0x39 0x37 0x35 0x04 0x00 0x00 0x00 0x80490d4 <hello3>: 0x31 0x39 0x37 0x35 0x04 0x00 0x00 0x00 Did you say you were taking a data storage class? There is some data storage... Pretty cool huh? Hours of fun! Ok so what about the strange character printed by the first write. Well look at the 4 bytes stored at 'hello' 0xb7 0x07 0x00 0x00 Now check you ascii chart. (really go get one if you don't have one) None of those byte values is a 'printable' character. Only values between 0x20 and 0x7f (32 thru 127 decimal) are printable. Values below 0x20 are special ascii control codes, some of them could even mess up your screen so you'd have to shut down that xterm or reboot! Most terminals these days are prevented from printing potentially dangerous characters, so I get a wierd reversed oval with a question mark in it , probably for the 0x07... and nothing prints for the other three... Your output may be different in that regard. Does that answer that for now??? Anyhow , those are the 4 bytes as stored sequentially in memory. But they look backward you say? Why yes they do. That is called endianness and how intel computers store integer values. (long story there) "But how come my 1975 was stored in memory like that instead of 0x01 0x09 0x07 0x05 or somesuch. Well let's look at that because it essential that you 'get it'. Remember that hello was declared as an .int which give it the 4 byte size and as an integer it is stored as a numeric value and NOT as the ascii for 1975 hence the values in the bytes shown above. Now for word size look at that: (gdb) x /xw 0x80490c4 0x80490c4 <hello>: 0x000007b7 ( Note the 'w' directs that a 'word' size (4 bytes) be shown. ) So there is a hex representation of decimal 1975 stored in 4 bytes (32 bits). (Do you now how to do hex yet? It's time to learn , google up a tutorial) Ok , the neat thing about hex is that it fits binary so well and binary is how everything in a computer works,, ones and zeros... Here's that hex in binary: 0 0 0 0 0 7 b 7 0000 0000 0000 0000 0000 0111 1011 0111 That binary representation is exactly how the bits are set in memory EXCEPT it is backwards (as far as lowest address to highest address). 1110 1101 1110 0000 0000 0000 0000 0000 7 b 7 0 0 0 0 0 The values are are diplayed to us in human readable order! Even the byte representation! Hex gets easier to work with the more you work with it... Soon you'll not want decimal for much of this kind of observation.
So there you go! Now continue stepping through the program watch it work.
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  
Old 01-Jan-2009, 01:01
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

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:
section .data
 
hello: .int 1975 #an int is 4 bytes
hello_len: .int . - hello
 
hello2: .ascii "1975" #these are 4 bytes
hello2_len: .int . - hello2 #note the order of each in output
 
hello3: .byte 0x31, 0x39, 0x37, 0x35 #these are 4 bytes
hello3_len: .int . - hello3 #note the order of each in output
this i s how i modified it
CPP / C++ / C Code:
section .data
 
hello: .int 19756 #an int is 4 bytes
hello_len: .int . - hello
 
hello2: .ascii "19756" #these are 4 bytes
hello2_len: .int . - hello2 #note the order of each in output
 
hello3: .byte 0x31, 0x39, 0x37, 0x35,0x36 #these are 5 bytes
hello3_len: .int . - hello3 #note the order of each in output
then my hello is 34 now this is the declaration again
CPP / C++ / C Code:
section .data
 
hello: .int 34 #an int is 4 bytes
hello_len: .int . - hello
 
hello2: .ascii "34" #these are 4 bytes
hello2_len: .int . - hello2 #note the order of each in output
 
hello3: .byte 0x33, 0x34 #these are 4 bytes
hello3_len: .int . - hello3 #note the order of each in output
and the same for hello =3 this is my gdb output :
CPP / C++ / C Code:
Value is (19756==4d2ch)
 
0x80490c4 <hello>:    0x2c    0x4d    0x00    0x00    0x04    0x00    0x00    0x00
0x80490c8 <hello_len>:    0x04    0x00    0x00    0x00    0x31    0x39    0x37    0x35
 
0x80490cc <hello2>:    0x31    0x39    0x37    0x35    0x36    0x05    0x00    0x00
0x80490d1 <hello2_len>:    0x05    0x00    0x00    0x00    0x31    0x39    0x37    0x35
 
0x80490d5 <hello3>:    0x31    0x39    0x37    0x35    0x36    0x05    0x00    0x00
0x80490da <hello3_len>:    0x05    0x00    0x00    0x00    0x00    0x00    0x01    0x00
 
Value is (34==22h) 
 
0x80490c4 <hello>: 0x22 0x00 0x00 0x00 0x04 0x00 0x00 0x00
0x80490c8 <hello_len>:0x04    0x00 0x00 0x00 0x33 0x34 0x02 0x00
 
0x80490cc <hello2>: 0x33 0x34 0x02 0x00 0x00 0x00 0x33 0x34
0x80490ce <hello2_len>:0x02 0x00 0x00 0x00 0x33 0x34    0x02 0x00
 
0x80490d2 <hello3>: 0x33 0x34 0x02 0x00 0x00 0x00 0x01 0x00
0x80490d4 <hello3_len>:0x02 0x00 0x00 0x00 0x01 0x00 0x00 0x00
 
Value is ( 3 =3h) 
 
0x80490c4 <hello>: 0x03 0x00 0x00 0x00 0x04 0x00 0x00 0x00
0x80490c8 <hello_len>:0x04    0x00 0x00 0x00 0x33 0x01 0x00 0x00
 
0x80490cc <hello2>: 0x33 0x01 0x00 0x00 0x00 0x33 0x01 0x00
0x80490cd <hello2_len>:0x01 0x00 0x00 0x00 0x33 0x01 0x00 0x00
 
0x80490d1 <hello3>: 0x33 0x01 0x00 0x00 0x00 0x00 0x00 0x01
0x80490d2 <hello3_len>:0x01 0x00 0x00 0x00 0x00 0x00 [color=blue]0x01[/color] 0x00
i will assume this ?
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  
Old 01-Jan-2009, 01:39
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
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 to see you are playing around!
Yes 34 decimal is 22 hex:
Code:
(32) (+2) = 34 decimal 0010 0010 (20) (+2) = 22 hex I think you should make you posted output more clear next time. It's pretty hard to follow what you have there. Your 'hello: .int 34' is the 0x22 0x00 0x00 0x00 as shown in this one: 0x80490c4 <hello>: 0x22 0x00 0x00 0x00 0x04 0x00 0x00 0x00 The 0x04 0x00 0x00 0x00 is the hello_len You are showing 8 bytes , so it shows 2 ints worth of space...
keep playing!
  #46  
Old 01-Jan-2009, 01:58
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

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  
Old 01-Jan-2009, 13:22
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
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?


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:
... My EXACT data declarations: hello: .int 34 hello_len: .int . - hello hello2: .ascii "1975" hello2_len: .int . - hello2 ... My EXACT gdb input / output for each item I want to show or have questions about: (gdb) info address hello Symbol "hello" is at 0x80490c4 in a file compiled without debugging. (gdb) info address hello_len Symbol "hello_len" is at 0x80490c8 in a file compiled without debugging. ... These are the actual stored data values in the 4 bytes used for each: (gdb) x /4xb 0x80490c4 0x80490c4 <hello>: 0x22 0x00 0x00 0x00 (gdb) x /4xb 0x80490c8 0x80490c8 <hello_len>: 0x04 0x00 0x00 0x00 ... Now examine 8 bytes beginning at 'hello': (gdb) x /8xb 0x80490c4 0x80490c4 <hello>: 0x22 0x00 0x00 0x00 0x04 0x00 0x00 0x00 ... |--- here is hello ---| |--- and hello_len ---| ... Now examine 16 bytes beginning at 'hello': (gdb) x /16xb 0x80490c4 ... |--- hello and ---| |--- hello_len ---| 0x80490c4 <hello>: 0x22 0x00 0x00 0x00 0x04 0x00 0x00 0x00 0x80490cc <hello2>: 0x31 0x39 0x37 0x35 0x04 0x00 0x00 0x00 ... |--- hello2 and ---| |--- hello2_len ---|
You see? All the information you might need is shown there.
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:
3-why the length of hello and hello_len is 64 bits not 32bits
What makes you think that?
Last edited by Howard_L : 01-Jan-2009 at 13:58.
  #48  
Old 01-Jan-2009, 22:54
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

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:
hello: .int  34 : this is nothing more that 32 bits integer 
with a value of 34(decimal) 
if i wanted the hex value it should be declared that way .int 0x22
the hello_len:
.int . -hello
 (this will count how many bytes my hello int will use which is 4)
as of the order of my data section hello will occupay let's say 
memory address (0x000000) so hello_len will be 0x000004)...
So sorry for my last idiocracy, moving on to more of the same (LOL)
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:
0x80490c4 <hello>:  0x22   0x00    0x00   0x00
// my hello2 is only two byte.   
0x80490cc <hello2>: 0x33   0x34  
 // hello2 stops here really it is only 2 bytes 
(u may wanna comment here if it is true 
how we can convert my 0x22 (integer ) to 0x33 0x34 (ascii) so i can print in my screen:
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  
Old 02-Jan-2009, 01:20
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
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?


Code:
re: as soon as i get home i said why am i asking very stupid questions why ?? I do it too. I find if I sit on things a day I avoid a lot of that. ----- re: // my hello2 is only two byte. Ok I see now... you still should have shown the declarations: hello2 .byte 0x33, 0x34 hello2_len . - hello2 Then there would not have to be any 'assuming' going on to waste time... Also you are still NOT showing the directives used for the outputyou show: x /4xb address YOU know how you got it , but I have to assume I know , and other readers don't! ----- Would you mind using the correct spelling 'you' instead of 'u'. (read the guidelines) This is a 'language' forum and it is, after all, proper syntax: ) ----- re: how we can convert my 0x22 to 0x33 0x34 so i can print in my screen... Oh boy so here we are... I would take this approach: So you want to print a decimal representation for the value. Your initial target in this case will be the integer 34 decimal. Lets say you want your routine to handle unsigned values up to 1 byte in size. A one byte decimal value could have a maximum value of 255. So it could have up to three digits which will need to be printed. Digits for: hundreds , tens and ones. Lets use that value 255 for an example. So you see how many hundreds: 255 / 100 = 2 Print or save the ascii digit for that value : 2 + 0x30 = 0x32 Subtract those hundreds : 255 - (2 * 100) = 55 See how many tens : 55 / 10 = 5 Print or save ascii for that: 5 + 0x30 = 0x35 Subtract again : 55 - (5 * 10) = 5 Convert the remaining ones : 5 + 0x30 = 0x35 So there you could have already printed you 0x32 0x35 0x35 or You could have them stored in a string and print them all at once... Does that make sense to you? So start to write pseudocode to accomplish these things. Think about it a day before posting back... Sleep on it! Good night...
  #50  
Old 02-Jan-2009, 12:36
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

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:
.section .data
num  : .int 0x7c 
item1:	.byte 0x0
item2: .byte 0x0
item3: .byte 0x0
.section .text
.globl _start                                  
_start: #beg of compiling
nop
xorl %eax,%eax
xorl %ebx,%ebx
xorl %ecx,%ecx
xorl %edx,%edx 

movl num,%eax # moving the decimal 124 to eax
movl $0x64,%ecx # moving the decimal 100 to ecx
divl %ecx	# dividing eax+edx : ecx
movl %eax,%ebx	# result of the div 124 /100 =1 is moved to ebx =1
movb %bl,item1
movl %edx,%eax	#reminder of div 124/100 =24 is moved back to eax =24

xorl %ecx,%ecx	# zero each ecx
movl $0xa,%ecx  #moving decimal 10 to ecx
xorl %edx,%edx
divl %ecx	#dividing eax by ecx = 24/10
movb %al,item2  #moving the byte 2 from eax to item2

xorl %ecx,%ecx	#zero ecx
movl $0x1,%ecx	#moving 1 into ecx
movl %edx,%eax	# moving the reminder of 24/10 =4 into eax
xorl %edx,%edx	#zero edx
divl %ecx	#dividing 4/1
movb %al,item3	#moving al to item3

xorl %eax,%eax
xorl %ebx,%ebx
xorl %ecx,%ecx
xorl %edx,%edx 

add $0x30,item1	#converting from numeral to ascii byte
add $0x30,item2
add $0x30,item3

movl $4,%eax	# calling write 
movl $1,%ebx	# return value in %ecb
leal item1,%ecx	# still not knowing what is this really
movl $3,%edx	#number of byte to be read starting at the memory
		#reserved by item then countin 3 bytes up 
int $0x80

xorl %eax,%eax
xorl %ebx,%ebx
xorl %ecx,%ecx
xorl %edx,%edx 
movl $1,%eax
movl $0,%ebx
int $0x80
Till i hear from you, thanks.
 
 

Recent GIDBlogProgramming ebook direct download available 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 14:47.


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