Saturday, January 21, 2012

Data Types used in .DATA section

The following are the data types which are used in the .DATA section
All these spaces are reserved at the Compile Time

.byte = 1 byte
.ascii = string
.asciz = Null terminated string
.int = 32 bit integer
.short = 16 bit integer
.float = Single precision floating point number
.double = Double precision floating point number

The following are the data types which are used in the .BSS section
All these spaces are allocated at the Run Time
.comm - declares common memory area
.lcomm - declares a local common memory area

The program starts here.

bala@bala-laptop:~/ASM$ cat variable.s
#This program shows how to use Data types.
.data
    HelloEarth:
        .ascii "HelloEarth"
    ByteLocation:
        .byte 50
    Int32:
        .int 5
    Int16:
        .short 5
    Float:
        .float 50.55
    IntegerArray:
        .int 50,55,60,65,70
.bss
    .comm LargeBuff, 1000
.text
   
    .globl _start
    _start:
        nop
        #Exit Systemcall to exit the program
        movl $1, %eax
        movl $0, %ebx
        int $0x80

bala@bala-laptop:~/ASM$ as -gstabs -o variable.o variable.s
bala@bala-laptop:~/ASM$ ld -o variable variable.o
bala@bala-laptop:~/ASM$ gdb ./variable
Let us set a break point
(gdb) break *_start+1
Breakpoint 1 at 0x4000b1: file variable.s, line 23.
(gdb) run
Starting program: /home/bala/ASM/variable
Breakpoint 1, _start () at variable.s:23
23            movl $1, %eax

(gdb) info variables
All defined variables:
Non-debugging symbols:
0x00000000006000c0  HelloEarth
0x00000000006000ca  ByteLocation
0x00000000006000cb  Int32
0x00000000006000cf  Int16
0x00000000006000d1  Float
0x00000000006000d5  IntegerArray
0x00000000006000f0  LargeBuff

(gdb) x/11cb 0x00000000006000c0
0x6000c0 :    72 'H'    101 'e'    108 'l'    108 'l'    111 'o'    69 'E'    97 'a'    114 'r'
0x6000c8 :    116 't'    104 'h'    50 '2'

(gdb) x/1db 0x00000000006000ca
0x6000ca :    50
(gdb) x/1dw 0x00000000006000cb
0x6000cb :    5
(gdb) x/1dh 0x00000000006000cf
0x6000cf :    5
(gdb) x/1fw 0x00000000006000d1
0x6000d1 :    50.5499992
(gdb) x/5dw 0x00000000006000d5
0x6000d5 :    50    55    60    65
0x6000e5 :    70

(gdb) x/100db 0x00000000006000f0
0x6000f0 :    0    0    0    0    0    0    0    0
0x6000f8 :    0    0    0    0    0    0    0    0
0x600100 :    0    0    0    0    0    0    0    0
0x600108 :    0    0    0    0    0    0    0    0
0x600110 :    0    0    0    0    0    0    0    0
0x600118 :    0    0    0    0    0    0    0    0
0x600120 :    0    0    0    0    0    0    0    0
0x600128 :    0    0    0    0    0    0    0    0
0x600130 :    0    0    0    0    0    0    0    0
0x600138 :    0    0    0    0    0    0    0    0
0x600140 :    0    0    0    0    0    0    0    0
0x600148 :    0    0    0    0    0    0    0    0

---Type to continue, or q to quit---

No comments:

Post a Comment