CSC231 Listing & Hexdump Files for helloWorld2.asm
(Redirected from CSC231 Listing File helloWorld2.lst)
--D. Thiebaut (talk) 11:19, 8 September 2014 (EDT)
Contents
Source File
;;; ; helloWorld2.asm
;;; ; D. Thiebaut
;;; ;
;;; ; Displays a simple "Hello World" message on the screen
;;; ;
;;; ; to assemble and run:
;;; ;
;;; ; nasm -f elf -F stabs helloWorld2.asm
;;; ; ld -melf_i3896 -o helloWorld2 helloWorld2.o
;;; ; ./helloWorld2
;;; ; -------------------------------------------------------------------
;; %include files here...
;;; ------------------------------------------------------------
;;; data areas
;;; ------------------------------------------------------------
section .data
mesg db "Hello, World!", 10
MSGLEN equ $-mesg
;;; ------------------------------------------------------------
;;; code area
;;; ------------------------------------------------------------
section .text
global _start
_start:
mov eax, 4 ; O.S, write a string
mov ebx, 1 ; write to stdout
mov edx, MSGLEN ; length of message
mov ecx, mesg ; string to print
int 0x80 ; call Linux
;;; exit()
mov eax,1
mov ebx,0
int 0x80 ; final system call
Listing File
You can get a listing of your assembly language program by adding the - l (minus ell) switch to your nasm command. - l means "generate a listing":
nasm -f elf -l helloWorld2.lst helloWorld2.asm
You should have a new file called helloWorld2.lst in your directory.
1 ;;; ; helloWorld.asm
2 ;;; ; D. Thiebaut
3 ;;; ;
4 ;;; ; Displays a simple "Hello World" message on the screen
5 ;;; ;
6 ;;; ; to assemble and run:
7 ;;; ;
8 ;;; ; nasm -f elf -F stabs helloWorld2.asm
9 ;;; ; ld -melf_i3896 -o helloWorld2 helloWorld2.o
10 ;;; ; ./helloWorld2
11 ;;; ; -------------------------------------------------------------------
12
13 ;; %include files here...
14
15
16 ;;; ------------------------------------------------------------
17 ;;; data areas
18 ;;; ------------------------------------------------------------
19
20 section .data
21 00000000 48656C6C6F2C20576F- mesg db "Hello, World!", 10
22 00000009 726C64210A
23 MSGLEN equ $-mesg
24
25
26
27 ;;; ------------------------------------------------------------
28 ;;; code area
29 ;;; ------------------------------------------------------------
30
31 section .text
32 global _start
33
34 _start:
35 00000000 B804000000 mov eax, 4 ; O.S, write a string
36 00000005 BB01000000 mov ebx, 1 ; write to stdout
37 0000000A BA0E000000 mov edx, MSGLEN ; length of message
38 0000000F B9[00000000] mov ecx, mesg ; string to print
39
40 00000014 CD80 int 0x80 ; call Linux
41
42
43 ;;; exit()
44
45 00000016 B801000000 mov eax,1
46 0000001B BB00000000 mov ebx,0
47 00000020 CD80 int 0x80 ; final system call
Hexdump Output
Hexdump is a linux command that takes a file and displays its contents in a raw form, as a collection of numbers representing each byte.
hexdump -v -C helloWorld2
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
00000010 02 00 03 00 01 00 00 00 80 80 04 08 34 00 00 00 |............4...|
00000020 dc 00 00 00 00 00 00 00 34 00 20 00 02 00 28 00 |........4. ...(.|
00000030 06 00 03 00 01 00 00 00 00 00 00 00 00 80 04 08 |................|
00000040 00 80 04 08 a2 00 00 00 a2 00 00 00 05 00 00 00 |................|
00000050 00 10 00 00 01 00 00 00 a4 00 00 00 a4 90 04 08 |................|
00000060 a4 90 04 08 0e 00 00 00 0e 00 00 00 06 00 00 00 |................|
00000070 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000080 b8 04 00 00 00 bb 01 00 00 00 ba 0e 00 00 00 b9 |................|
00000090 a4 90 04 08 cd 80 b8 01 00 00 00 bb 00 00 00 00 |................|
000000a0 cd 80 00 00 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 |....Hello, World|
000000b0 21 0a 00 2e 73 79 6d 74 61 62 00 2e 73 74 72 74 |!...symtab..strt|
000000c0 61 62 00 2e 73 68 73 74 72 74 61 62 00 2e 74 65 |ab..shstrtab..te|
000000d0 78 74 00 2e 64 61 74 61 00 00 00 00 00 00 00 00 |xt..data........|
000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000100 00 00 00 00 1b 00 00 00 01 00 00 00 06 00 00 00 |................|
00000110 80 80 04 08 80 00 00 00 22 00 00 00 00 00 00 00 |........".......|
00000120 00 00 00 00 10 00 00 00 00 00 00 00 21 00 00 00 |............!...|
00000130 01 00 00 00 03 00 00 00 a4 90 04 08 a4 00 00 00 |................|
00000140 0e 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 |................|
00000150 00 00 00 00 11 00 00 00 03 00 00 00 00 00 00 00 |................|
00000160 00 00 00 00 b2 00 00 00 27 00 00 00 00 00 00 00 |........'.......|
00000170 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 |................|
00000180 02 00 00 00 00 00 00 00 00 00 00 00 cc 01 00 00 |................|
00000190 b0 00 00 00 05 00 00 00 07 00 00 00 04 00 00 00 |................|
000001a0 10 00 00 00 09 00 00 00 03 00 00 00 00 00 00 00 |................|
000001b0 00 00 00 00 7c 02 00 00 3c 00 00 00 00 00 00 00 |....|...<.......|
000001c0 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 |................|
000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001e0 80 80 04 08 00 00 00 00 03 00 01 00 00 00 00 00 |................|
000001f0 a4 90 04 08 00 00 00 00 03 00 02 00 01 00 00 00 |................|
00000200 00 00 00 00 00 00 00 00 04 00 f1 ff 11 00 00 00 |................|
00000210 a4 90 04 08 00 00 00 00 00 00 02 00 16 00 00 00 |................|
00000220 0e 00 00 00 00 00 00 00 00 00 f1 ff 00 00 00 00 |................|
00000230 00 00 00 00 00 00 00 00 04 00 f1 ff 1d 00 00 00 |................|
00000240 80 80 04 08 00 00 00 00 10 00 01 00 24 00 00 00 |............$...|
00000250 b2 90 04 08 00 00 00 00 10 00 02 00 30 00 00 00 |............0...|
00000260 b2 90 04 08 00 00 00 00 10 00 02 00 37 00 00 00 |............7...|
00000270 b4 90 04 08 00 00 00 00 10 00 02 00 00 68 65 6c |.............hel|
00000280 6c 6f 57 6f 72 6c 64 32 2e 61 73 6d 00 6d 65 73 |loWorld2.asm.mes|
00000290 67 00 4d 53 47 4c 45 4e 00 5f 73 74 61 72 74 00 |g.MSGLEN._start.|
000002a0 5f 5f 62 73 73 5f 73 74 61 72 74 00 5f 65 64 61 |__bss_start._eda|
000002b0 74 61 00 5f 65 6e 64 00 |ta._end.|
000002b8
Hexdump of a Text File
- What does a text file look like, when it is stored in the file system of a Linux computer?
- Well, let's create a simple text file with emacs, and save it to disk. Here's an example of some text saved in a file called sampleText.txt:
Mary Had a Little Lamb --Song by Stevie Ray Vaughan Mary had a little lamb His fleece was black as coal, yeah And everywhere the child went That little lamb was sure to go now.
Here's the output of hexdump:
hexdump -v -C sampleText.txt 00000000 4d 61 72 79 20 48 61 64 20 61 20 4c 69 74 74 6c |Mary Had a Littl| 00000010 65 20 4c 61 6d 62 0a 20 20 2d 2d 53 6f 6e 67 20 |e Lamb. --Song | 00000020 62 79 20 53 74 65 76 69 65 20 52 61 79 20 56 61 |by Stevie Ray Va| 00000030 75 67 68 61 6e 0a 0a 4d 61 72 79 20 68 61 64 20 |ughan..Mary had | 00000040 61 20 6c 69 74 74 6c 65 20 6c 61 6d 62 0a 48 69 |a little lamb.Hi| 00000050 73 20 66 6c 65 65 63 65 20 77 61 73 20 62 6c 61 |s fleece was bla| 00000060 63 6b 20 61 73 20 63 6f 61 6c 2c 20 79 65 61 68 |ck as coal, yeah| 00000070 0a 41 6e 64 20 65 76 65 72 79 77 68 65 72 65 20 |.And everywhere | 00000080 74 68 65 20 63 68 69 6c 64 20 77 65 6e 74 0a 54 |the child went.T| 00000090 68 61 74 20 6c 69 74 74 6c 65 20 6c 61 6d 62 20 |hat little lamb | 000000a0 77 61 73 20 73 75 72 65 20 74 6f 20 67 6f 20 6e |was sure to go n| 000000b0 6f 77 2e 0a 0a |ow...| 000000b5
- Questions
-
- Does the text file contain a header, similar to the header of the executable above?
- Are there extra bytes in the file, besides the text of the song?
- How many Return characters are at the end of the file?
- How long is the file, in bytes?
Challenge of the Day
Look at the hexdump of an executable file. Can you tell anything about it?
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF............| 00000010 02 00 03 00 01 00 00 00 80 80 04 08 34 00 00 00 |............4...| 00000020 dc 00 00 00 00 00 00 00 34 00 20 00 02 00 28 00 |........4. ...(.| 00000030 06 00 03 00 01 00 00 00 00 00 00 00 00 80 04 08 |................| 00000040 00 80 04 08 a2 00 00 00 a2 00 00 00 05 00 00 00 |................| 00000050 00 10 00 00 01 00 00 00 a4 00 00 00 a4 90 04 08 |................| 00000060 a4 90 04 08 10 00 00 00 10 00 00 00 06 00 00 00 |................| 00000070 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000080 b8 04 00 00 00 bb 01 00 00 00 b9 a4 90 04 08 ba |................| 00000090 10 00 00 00 cd 80 bb 00 00 00 00 b8 01 00 00 00 |................| 000000a0 cd 80 00 00 56 31 76 61 23 46 72 65 73 68 23 50 |....V1va#Fresh#P| 000000b0 41 53 54 41 00 2e 73 79 6d 74 61 62 00 2e 73 74 |ASTA..symtab..st| 000000c0 72 74 61 62 00 2e 73 68 73 74 72 74 61 62 00 2e |rtab..shstrtab..| 000000d0 74 65 78 74 00 2e 64 61 74 61 00 00 00 00 00 00 |text..data......| 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000100 00 00 00 00 1b 00 00 00 01 00 00 00 06 00 00 00 |................| 00000110 80 80 04 08 80 00 00 00 22 00 00 00 00 00 00 00 |........".......| 00000120 00 00 00 00 10 00 00 00 00 00 00 00 21 00 00 00 |............!...| 00000130 01 00 00 00 03 00 00 00 a4 90 04 08 a4 00 00 00 |................| 00000140 10 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 |................| 00000150 00 00 00 00 11 00 00 00 03 00 00 00 00 00 00 00 |................| 00000160 00 00 00 00 b4 00 00 00 27 00 00 00 00 00 00 00 |........'.......| 00000170 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 |................| 00000180 02 00 00 00 00 00 00 00 00 00 00 00 cc 01 00 00 |................| 00000190 b0 00 00 00 05 00 00 00 07 00 00 00 04 00 00 00 |................| 000001a0 10 00 00 00 09 00 00 00 03 00 00 00 00 00 00 00 |................| 000001b0 00 00 00 00 7c 02 00 00 3d 00 00 00 00 00 00 00 |....|...=.......| 000001c0 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 |................| 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001e0 80 80 04 08 00 00 00 00 03 00 01 00 00 00 00 00 |................| 000001f0 a4 90 04 08 00 00 00 00 03 00 02 00 01 00 00 00 |................| 00000200 00 00 00 00 00 00 00 00 04 00 f1 ff 0b 00 00 00 |................| 00000210 a4 90 04 08 00 00 00 00 00 00 02 00 14 00 00 00 |................| 00000220 10 00 00 00 00 00 00 00 00 00 f1 ff 00 00 00 00 |................| 00000230 00 00 00 00 00 00 00 00 04 00 f1 ff 1e 00 00 00 |................| 00000240 80 80 04 08 00 00 00 00 10 00 01 00 25 00 00 00 |............%...| 00000250 b4 90 04 08 00 00 00 00 10 00 02 00 31 00 00 00 |............1...| 00000260 b4 90 04 08 00 00 00 00 10 00 02 00 38 00 00 00 |............8...| 00000270 b4 90 04 08 00 00 00 00 10 00 02 00 00 73 6e 6f |.............sno| 00000280 6f 70 2e 61 73 6d 00 70 61 73 73 77 6f 72 64 00 |op.asm.password.| 00000290 70 61 73 73 77 64 4c 65 6e 00 5f 73 74 61 72 74 |passwdLen._start| 000002a0 00 5f 5f 62 73 73 5f 73 74 61 72 74 00 5f 65 64 |.__bss_start._ed| 000002b0 61 74 61 00 5f 65 6e 64 00 |ata._end.|