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
  #31  
Old 17-Dec-2008, 23:47
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:
heikel@heikel-desktop:~/Assembly$ (gdb) break *_start+5 bash: syntax error near unexpected token `break'
...well of course... the
(gdb) <-- is the prompt once you've started gdb.
You need to start gdb with the file you want to load as an argument first:
Code:
heikel@heikel-desktop:~/Assembly$ gdb ./beg
...then your 'break *_start+5' line should work when typed after the '(gdb)' prompt.
Quote:
no way to access the higher EAX(16 bits) so we kinda still dealing wiith the AX
Code:
You can use any of these: | EAX ( all 32 BITS) | | |------- AX (16) ---| | | AH(8) | AL(8) | |0000 0000 0000 0000 0000 0000 0000 0000| You can use ah and al at the same time... but of course you will need to be careful. I believe that would be considered risky and so a bad practice to dual use. You've noticed how careful the pros are about zeroing out registers before using them... (never assume) =========================================================== Ok so the eflags. If you are not familiar with 'bit fields' yet it is time... Get out your book and look up 'bit fields' or 'masks' or 'bitwise operators'... It is a way of storing several 'true or false' values in one piece of data. For example a byte has 8 bits which can be either 1 or 0 (on or off) , (T or F) 1 byte= 8 bits: 0000 0000 or 0000 0001 or ....(256 different combos) So you can see that 8 different things can be specified. This scheme is used for many things like the makeup of colors (rgb), or like in linux our file 'permissions'. So the EFLAGS register is the same kind of thing. Google turns up lots of references. I used a couple for the folloing information: This part (kinda) copied from: http://www.sandpile.org/ia32/eflags.htm 16/32bit FLAGS/EFLAGS register |---------------------------- 32 bit ------------------------------| | I guess these are eflags | and these are just flags | |-------16 bit (8086) -----------| 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 0 0 0 0 0 0 0 0 0 0 I V V A V R 0 NIOPL O D I T S Z 0 A 0 P 1 C | D I I C M F P F Copied from: http://www.ece.unm.edu/faculty/jimp/310/slides/micro_arch1.html Programmer Visible Architecture EFLAGS : Store the state of various conditions in the microprocessor. EFLAGS Register: The rightmost 5 flag bits and overflow change after many of the arithmetic and logic instructions execute. Data transfer and control instructions never change the flags. C (Carry) : - Holds the carry out after addition or the borrow after subtraction. - Also indicates error conditions. P (Parity) : - 0 for odd number of bits and 1 for even. - Obsolete feature of the 80x86. A (Auxiliary Carry) : - Highly specialized flag used by DAA and DAS instructions after BCD addition or subtraction. Z (Zero) : - 1 if the result of an arithmetic or logic instruction is 0. S (Sign) : - 1 if the sign of the result of an arith. or logic instruction is negative. T (Trap) : - Trap enable. The microprocessor interrupts the flow of instructions on conditions indicated by the debug and control registers. I (Interrupt) : - Controls the operation of the INTR (Interrupt request) pin. If 1, interrupts are enabled. Set by STI and CLI instructions. D (Direction) : - Selects with increment or decrement mode for the DI and/or SI registers during string instructions. If 1, registers are automatically decremented. Set by STD and CLD instructions. O (Overflow) : - Set for addition and subtraction instructions. ---------- 80286 and up: IOPL (I/O privilege level) : - It holds the privilege level at which your code must be running in order to execute any I/O-related instructions. 00 is the highest. NT (Nested Task) : - Set when one system task has invoked another through a CALL instruction in protected mode. ---------- 80386 and up: RF (Resume) : - Used with debugging to selectively mask some exceptions. VM (Virtual Mode) : - When 0, the CPU can operate in Protected mode, 286 Emulation mode or Real mode. When set, the CPU is converted to a high speed 8086. This bit has enormous impact. ---------- 80486SX and up: AC (Alignment Check) : - Specialized instruction for the 80486SX. ---------- Pentium and up: VIF (Virtual Interrupt Flag) : - Copy of the interrupt flag bit. VIP (Virtual Interrupt Pending) : - Provides information about a virtual mode interrupt. ID (Identification) : - Supports the CPUID instruction, which provides version number and manufacturer information about the microprocessor. ----------
Hope that helps Google around if not, and do check your book for bit fields etc...
Have fun!
  #32  
Old 19-Dec-2008, 03:35
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


Hi Howard i hope u r not annoyed by my beginner questions. i always try to know where i am, so i think it is time to know about the specific use for those registers EAX, EBX, ECX, EDX,
i think for example EAX takes the system call like if we pass the integer $4,%eax and call int $0,x80 then the kernel call the write function.
i think if u can go over quickly that will help me to understand them better
noe the part that stil confuse me is this one
CPP / C++ / C Code:
	.section .data
hello:	
	.ascii 	"Hello, world!\n"
hello_len:
	.long 	. - hello
	.section .text
	.globl _start
	
_start:
	xorl %ebx, %ebx	# i got the xor part so after this line ebx ==0....000(32 bit)	
	movl $4, %eax	# this is passing the int 4 which the write sys call	
	xorl %ebx, %ebx   # why this line again we already put ebx==0
	incl %ebx	 # %ebx = 1, fd = stdout # i don't get why ebx has to have $1 in it
	leal hello, %ecx # i did check leal in the appendix i hopt u will do better than the book lol
	movl hello_len, %edx # i think this is the line that needs more attention 
	int $0x80	 #
	
	## terminate program via _exit () system call 
	xorl %eax, %eax		# %eax = 0
	incl %eax		# %eax = 1 system call _exit ()
	xorl %ebx, %ebx		# %ebx = 0 normal program return code
	int $0x80		# execute system call _exit ()
thanks howard please don't be annoyed
  #33  
Old 20-Dec-2008, 01:01
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:
No annoyance here,, your questions help me re-learn things I think I know. Don't forget I am fairly new to this too! But I would ask that you not use tabs in your code. They sometimes won't show well on the website (as said in guidelines) and when I paste your code into my editor to try it out I have to re-edit the tabs into spaces because my tabs are set to different width. So always use spaces instead of tabs. ---------- re: ... specific use of registers EAX, EBX, ECX, EDX. Ha, that's just it! Their specific usages are whatever the function using them specifies! I, as a programmer, must be mindful of these specs and try to write code that interfaces with them well. There seem to be some general trends which differ between one OS and another. System opcodes have their 'interface' (prototype , declaration) , any function you write will have it's 'interface'. That is, they each use specific registers for both function arguments and return value. From what I know so far and using the linux write opcode as a guide I can see: ----- EAX - used for opcode number (write's is 4) - used for return values (watch out for this! usually just al is effected) EBX - used for output device (stdout = 1) ECX - pointer to data for function to work with (a string) EDX - is a 'count' value (length of string) You will also soon be seeing these for manipulating the stack: ESP - holds the address of 'top' of the stack. EBP - used to hold the base of the present 'stack frame' ... and I have not used these yet but ... EDI - Holds the base destination pointer for string instructions. ESI - Holds the base source pointer for string instructions. ----- You can see all of these in gdb by typing this command: (gdb) info register ==================== re: xorl %ebx, %ebx # why this line again we already put ebx==0 Right I remember that, it must be a typo, I think the first xorl should be: xorl %eax, %eax ----- re: incl %ebx # %ebx= 1, fd= stdout #i don't get why ebx has to have $1 in it Well write copies data from one location to another. Look at the interface: man 2 write ...and I see: ssize_t write(int fd, const void *buf, size_t count); The first param goes in EBX , the second in ECX and the third EDX. (I think all linux syscall parameters go into the registers in the same order like this.) Reading on in the man page I see: DESCRIPTION write() writes up to count bytes to the file referenced by the file descriptor fd from the buffer starting at buf... On success, the number of bytes written are returned... So an 'fd' goes in EBX. 'fd' stands for 'file descriptor'. When you open a file you get a pointer to the beginning of that file which we often name 'fd'. In Linux devices such as a printer or our beloved screen are handled the same way. At system startup the screen is given the file descriptor (pointer value) 1. On the system there is a link (like alias) created for this fd called stdout. You can find it the list printed when you type: ls -l /dev' lrwxrwxrwx 1 root root 15 Oct 16 13:03 /dev/stderr -> /proc/self/fd/2 lrwxrwxrwx 1 root root 15 Oct 16 13:03 /dev/stdin -> /proc/self/fd/0 lrwxrwxrwx 1 root root 15 Oct 16 13:03 /dev/stdout -> /proc/self/fd/1 You can see 2 other io devices stderr and stdin and their fd 'handle's. So the 1 says to write to stdout (the screen) as opposed to a file etc... ----- Re: leal hello, %ecx # do better description Lets look at a gdb of that,, ok so I step up to the leal: (gdb) 11 leal hello, %ecx Ok so that is ready to go, let's check some values (look closely) (gdb) info address hello Symbol "hello" is at 0x8049094 in a file compiled without debugging. (gdb) print /x $ecx $1 = 0x0 (gdb) step # ok we just executed the 'leal hello, %ecx' 12 movl hello_len, %edx # this will not be executed until the next 'step' is done. (gdb) print /x $ecx $3 = 0x8049094 So, %ecx now holds the address held in the variable 'hello'. Now we can 'examine' data at that address like this: (gdb) x /s $ecx 0x8049094 <hello>: "Hello, world!\n\016" With the /s format specifier the x command prints the zero terminated string. What's the \016 you say??? (I assume (hope) you know what '\n' is) Well x sees an Octal 16 in the byte after '\n' before a terminating zero. Octal 16 is dec (8+6) = 14 which is not printable and so shown as value instead. So how about a look at the bytes! : (gdb) x /20xb $ecx 0x8049094 <hello>: 0x48 0x65 0x6c 0x6c 0x6f 0x2c 0x20 0x77 0x804909c <hello+8>: 0x6f 0x72 0x6c 0x64 0x21 0x0a 0x0e 0x00 0x80490a4 <hello_len+2>: 0x00 0x00 0x00 0x00 Ok so get your ascii chart and translate. Following the 0x0a (\n) see the 0x0e. That is the \016 (14 decimal, e hex) Note that following that is the terminating zero! Ok so again you say "so what's with the \016 !!! I didn't put that in there! Well yes you did! with this: .section .data hello: .ascii "Hello, world!\n" hello_len: .long . - hello The value of hello_len was calculated and stored immediately following the last character you wanted stored in hello which was the '\n'. Note the tricky len calculation: . - hello The dot (.) represent the present address. Above we saw that 'hello' contained 0x8049094 so the dot represented 0x80490a2 at the calculation time, so subtract the addresses and you should get 14: 0xa2 1010 0010 binary 162 decimal - 0x94 or 1001 0100 148 e 0000 1110 14 ... and there you go, that's where the /016 comes from. Now you wonder why the hello_len: .long (4 bytes) is stored as shown above: 0x0e 0x00 0x00 0x00 0x00 0x00 endianness ... google it,,, enough of that, so what was the question? leal hello, %ecx # do better description Oh yeah, so you saw how that gets the address held in hello into %ecx. So that's what it does! It says: ----- leal M, I/R/M O/S/Z/A/C This takes a memory location given in the standard format, and, instead of loading the contents of the memory location, loads the computed address. For example: leal 5(%ebp,%ecx,1), %eax loads the address computed by 5 + %ebp + 1*%ecx and stores that in %eax ----- Well I haven't done much with pointer indexing/referencing methods yet. I have used 'movl $hello, %ecx' to do the same thing for the straight address. I'll see if I can get some idea of what the advantage of leal is. OK , I learned some stuff. See if you can follow this excercise. I've added these lines to your hello program: leal hello, %ecx # original line , copies string address to ecx movl $hello, %ecx movl hello, %ecx movl $2, %eax movl hello(, %eax, 4), %ecx leal hello(, %eax, 4), %ecx Now lets step through them with gdb and see what we can see. (remember that the instruction printed will not be done until the next 'step') Ok, I'll just step up to the first leal. (gdb) 13 leal hello, %ecx # original line , copies string address to ecx (gdb) info address hello Symbol "hello" is at 0x80490b4 in a file compiled without debugging. (gdb) print /x $ecx $1 = 0x0 (gdb) step 14 movl $hello, %ecx (gdb) print /x $ecx # This result from leal hello, %ecx $2 = 0x80490b4 # Address assigned to ecx correctly. (gdb) s 15 movl hello, %ecx (gdb) print /x $ecx # This result from movl $hello, %ecx $3 = 0x80490b4 # Address assigned to ecx correctly. (gdb) s 16 movl $2, %eax (gdb) print /x $ecx # This result from movl hello, %ecx $4 = 0x6c6c6548 # These are 4 values found at that address! # the ascii characters: l l e H (look 'em up) # so this is Not what we want. # note that the order is reversed. (endianness) # OK, Moving on, now we get to the indexing: # Note that eax holds the value 2. # What I will try to do is get the address which is offset from hello. # Think of the following like this hello(,plus two items, of size 4) # or hello(, 2, times 4) or (address of hello) + 8 bytes # So we know that hello holds the address 0x80490b4 # Now if we add 8 to that we get 0x80490bc Lets see what happens: (gdb) s 17 movl hello(, %eax, 4), %ecx (gdb) s 18 leal hello(, %eax, 4), %ecx (gdb) print /x $ecx # This result from movl hello(, %eax, 4), %ecx $6 = 0x646c726f # Well this is not in the address range is it... # Is it ascii again? # Let's try a nifty 'examine' command again: (gdb) x /16xb 0x80490b4 # examine 16 bytes starting at address of hello 0x80490b4 <hello>: 0x48 0x65 0x6c 0x6c 0x6f 0x2c 0x20 0x77 0x80490bc <hello+8>: 0x6f 0x72 0x6c 0x64 0x21 0x0a 0x0e 0x00 # Well do you see the 4 bytes above in that output? # Yes! So that's NOT what we want is it... # so let's go ahead and step through that leal: (gdb) s 23 movl hello_len, %edx (gdb) print /x $ecx $8 = 0x80490bc # hey hey , check it out! Same as predicted above! # and just for haha's here is the zero terminated # string found at that location: (gdb) x /s 0x80490bc 0x80490bc <hello+8>: "orld!\n\016" #### coool dude! it all makes sense! # Epilog: leal is able to handle pointer indexing , , movl is not. # So it would be better to get used to using leal. ##### The End of that leal part.... #### Ok and lastly: Re: movl hello_len, %edx # i think this is the line that needs more attention I don't! I think it's been covered above re-re-reread! That should keep you busy for a while , (it did me) , Good Night!
  #34  
Old 21-Dec-2008, 04:44
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


Your last two posts are like a chapter itself so i am working on them i am at work so i just read it briefly i did not grap a pen and a paper to analyze it step by step but here my two main concern now :
1 - i typed man 2 write i got an error message saying manual not installed or not found and i am wondering how to install it
2- when i type : as -gstabs example. s -o example .o
then ld example.o -o example
then gdb ./example
this is what i got in my screen <gdb>......
now if i modify the code again and try to compile it and link it :i got an error nessage saying : as not a valid command so how to exit the gdb so i can compile again
now i got the week end to work on the posts really good
and i will set my goal to do this take a long variable and display it on the screen so if i am not mistaking i should convert the long to ascii then i can display it ? if i got stuck which i will lol i will ask you now i remmebred that this function :"ssize_t write(int fd, const void *buf, size_t count);"
i can indentify int fd, when it comes to const void * buf there where i have to tell you that i never see some like that in c++ and i don't know where is that. The same think will apply to (size_t count) also ssize_t write(arg1,arg2,arg3)is it a return type or a void type
your next post is crucial so i will be waiting ( i knwo i am asking too much and the reason is i could not use my man 2 write command thanks Howard
  #35  
Old 21-Dec-2008, 13:59
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?


Quote:
1 - i typed man 2 write... got message manual not installed... how to install it.
This is how they fit the initial ubuntu install onto one cd.
How to install would be a 'ubuntu support' question. Google that.
You can also try 'man 2 write' for the particular man page.
You could save the web page or copy/paste into editor for a smaller .txt file.

Quote:
2 - ... if i modify the code and try to compile/link it: i get message: as not a valid command
So, you are using two xterms, editing in one and trying to compile within gdb in the other? eg:
Code:
<gdb> as -gstabs example. s -o example .o
Right, You can't do that. To quit gdb first type:
Code:
<gdb> quit ...or the abbreviation: <gdb> q ...both work. Have you tried this yet: <gdb> help ...you will find 'quit' under <gdb> help support Re: i will set my goal to take a long variable and display it on the screen ...if i am not mistaking i should convert the long to ascii then i can display it ? Quite a goal! Yes convert to ascii and display. Re: this function: ssize_t write(int fd, const void *buf, size_t count); const void * buf ...i never see some like that in c++ (opinion: If you had some C background before C++ you would know what that means. I think a C background is very beneficial. Every programmer should have a K&R!) const is a C data qualifier which means that the data can't be changed (will remain constant). void* is a void pointer (address) , buf is just their little name for it. What it means is that it wants a pointer (*) to a block of bytes (buf) of any type (void) and it promises that it won't alter them (const) Re: The same think will apply to (size_t count) size_t is a global datatype , probably an unsigned 32 bit int. It's defined somwhere in the compiler running envronment (no time to look now) Re: ssize_t write(arg1,arg2,arg3) is it a return type or a void type The 'ssize_t write(' tells you it DOES have a return type of size_t. A void return type would be written: 'voind write('. By The Way , you will see that return show up in eax after execution. It should be number of characters written.
Gotta go good luck and Have Fun!
  #36  
Old 22-Dec-2008, 13:51
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


Hi, i know u may be going and not what ? lol
ok i am still doing the last two posts u did submit and this is what i got when i typed
CPP / C++ / C Code:
heikel@heikel-desktop:~/Assembly$ as -gstabs str.s -o str.o
heikel@heikel-desktop:~/Assembly$ ld str.o -o str
heikel@heikel-desktop:~/Assembly$ gdb ./str
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) print /x $ecx
No registers.
(gdb) info address hello
Symbol "hello" is at 0x80490a4 in a file compiled without debugging.
i am wondering why i did not get "$1 = 0x0" like u did in ur post
thanks i will be working at ur post till u submit a response also i am getting the ssize function.
So let me focus on that till ur next post. thanks again
  #37  
Old 25-Dec-2008, 10:27
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?


I think you should have thought and tried a bit more before sending this. You probably know this by now but:
Code:
Re: (gdb) print /x $ecx No registers.
"i am wondering why i did not get "$1 = 0x0" like u did in ur post"

That is because the program is not running at the time you are making that request. You need to:
- start gdb with the file.s to run
- then set a 'break' point,
- then 'run' and look at register states while running
- 'quit'
- make adjustments to source.s file and and recompile
- repeat

There is no ssize function in that program.
It's ssize_t and it is a datatype as I said above except I think it is signed.
  #38  
Old 27-Dec-2008, 01:56
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


hi,
Part 1:
CPP / C++ / C Code:
start gdb with the file.s to run 
i tought we use this command:
as -gstabs -sample.s -o sample.o
ld sample.o -o sample
gdb ./sample
CPP / C++ / C Code:
- then set a 'break' point,
i thought we use this command:
break *_start+5
[cpp]
- then 'run' and look at register states while running
[cpp]
it is here where i don't know what to type cuz if i type:
info registers it will says program has no registers
CPP / C++ / C Code:
- 'quit'
here we just type q for quit

Part 2:
i am looking how to convert a long var to ascii code
let is say my section data is like this:
CPP / C++ / C Code:
.section .data
obj:
.long 65
then to print it to the screen as 65 we should use the $4 system call
so where the address of the tag obj should go and where the value(using the $ sign is the immediate mode i think which retrieve the value of the tag if i am not mistaking?) should go ??
Part 3:
Merry Christmas for all Assembly Devs
  #39  
Old 27-Dec-2008, 16:55
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:
Here is exaclty what works for me: First here is a look at a simple x-86 assebly program to examine with gdb. (Note that this also gives a glimpse into working with single bytes in the al and bl registers): [me@myprompt]$ cat exit-1.s .file "samp.s" .section .bss .section .data .text .globl _start _start: nop # 'no operation': so that in gdb # 'break *_start+1' will stop at first line! movl %esp, %ebp # save base of stack pushl $0x01020304 popl %eax #### exit #### xorl %ebx, %ebx # zero out ebx movb %al, %bl # transfer return value xorl %eax, %eax # zero out the register incl %eax # 1 is the 'exit' syscall which # returns the value %bl # which is 1 byte (0-256 max) int $0x80 # make the call [me@myprompt]$ as -gstabs exit-1.s -o exit-1.o [me@myprompt]$ ld exit-1.o -o exit-1 [me@myprompt]$ ./exit-1 [me@myprompt]$ echo $? 4 OK , with me so far? See the return value? It's the low byte of eax: al Now we go for a run in gdb: [me@myprompt]$ gdb ./exit-1 GNU gdb Red Hat Linux (6.5-8.fc6rh) Copyright (C) 2006 Free Software Foundation, Inc. blah blah blah (gdb) break *_start+1 Breakpoint 1 at 0x8048055: file exit-1.s, line 10. (gdb) run Starting program: /asm/myex/exit-1 Breakpoint 1, _start () at exit-1.s:10 10 movl %esp, %ebp # save base of stack Current language: auto; currently asm (gdb) step _start () at exit-1.s:10 10 pushl $0x01020304 (gdb) step _start () at exit-1.s:10 10 pushl $0x01020304 (gdb) ##<--PRESSING RETURN HERE TO REPEAT LAST COMMAND _start () at exit-1.s:11 11 popl %eax (gdb) _start () at exit-1.s:14 14 xorl %ebx, %ebx # zero out ebx (gdb) info registers eax 0x1020304 16909060 ecx 0x0 0 edx 0x0 0 ebx 0x0 0 esp 0xbfe58100 0xbfe58100 ebp 0xbfe58100 0xbfe58100 esi 0x0 0 edi 0x0 0 eip 0x804805d 0x804805d <_start+9> eflags 0x212 [ AF IF ] cs 0x73 115 ss 0x7b 123 ds 0x7b 123 es 0x7b 123 fs 0x0 0 gs 0x0 0 (gdb) step 15 movb %al, %bl # transfer 1 byte return value (gdb) 16 xorl %eax, %eax # zero out the register (gdb) info registers eax 0x1020304 16909060 ecx 0x0 0 edx 0x0 0 ebx 0x4 4 esp 0xbfe58100 0xbfe58100 ebp 0xbfe58100 0xbfe58100 esi 0x0 0 edi 0x0 0 eip 0x8048061 0x8048061 <_start+13> eflags 0x246 [ PF ZF IF ] cs 0x73 115 ss 0x7b 123 ds 0x7b 123 es 0x7b 123 fs 0x0 0 gs 0x0 0 (gdb) p /x $eax $2 = 0x1020304
This should work the same way for you.
Make sure you do each of the commands and get similar results.
If you are still having difficulties showing registers in gdb and have TRIPLE checked that you are doing EXACTLY what is shown, please post everything shown in xterm during your trial.
  #40  
Old 30-Dec-2008, 18:23
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Assembly Tutorial?


Hi Howard
i need help to understand this instruction
leal M, I/R/M O/S/Z/A/C
This takes a memory location given in the standard format ( what is the standard format ??? ), and, instead of loading the contents
of the memory location, loads the computed address ( what he means here by computed address ???) . For example, leal 5(%ebp,%ecx,1),
%eax loads the address computed by 5 + %ebp + 1*%ecx and stores that in %eax

this is my code to print A into the screen
CPP / C++ / C Code:
	.section .data
hello:	
.int 65
hello_len:
	.int 	. - hello
	.section .text
	.globl _start
_start:
nop
xorl %eax,%eax
movl $4,%eax
xorl %ebx,%ebx
incl %ebx
leal hello,%ecx
movl hello_len,%edx
int $0x80
xorl %eax,%eax
incl %eax
xorl %ebx,%ebx
int $0x80
so if u can explain how 's the leal instruction operate on my variable hello and its memory address hello_len that would be a great step for me.
now what is going to make it even greater is the following lwt is say that i have an integer var called num like this
CPP / C++ / C Code:
.section .data
num:
int 1975
num_len:
.int 	. -num
now if we pass $4,%eax and call int 80 the compiler will look into ecx and get the address of the variable and the edx will hold the value of that variable that i called num so here where i don't know how to tell the compiler to look for the address of variable num and how to tell the comipler that num_len will point to the value of the address stored in num
hopefully i am getting something i already did dispay the "A" using the ascii code which 65
so the code posted did convert the 65 to char "A" the proble is how to tell the compiler to take my num=1975 and dispaly it ??? by the way 1975 is my birth year
see later thanks
 
 

Recent GIDBlogProblems with the Navy (Chiefs) 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 16:40.


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