Understanding listing fie in nasm program -
i don't understand why following program outputs: 356 , how connected listing file understanding. question,why segmentation fault happens when add "section .text" in second line?
1 global _start 2 3 section .data 4 00000000 03000000 x: dd 3 5 6 00000004 8b0d[00000000] _start: mov ecx, [x] 7 0000000a 000d[16000000] r: add byte [l+6], cl 8 00000010 c605[00000000]30 l: mov byte [x], 48 9 00000017 51 push ecx 10 00000018 b804000000 mov eax,4 11 0000001d bb01000000 mov ebx, 1 12 00000022 b9[00000000] mov ecx, x 13 00000027 ba01000000 mov edx,1 14 0000002c cd80 int 0x80 15 0000002e 59 pop ecx 16 0000002f e2d9 loop r,ecx 17 00000031 bb00000000 mov ebx,0 18 00000036 b801000000 mov eax,1 19 0000003b cd80 int 0x80
thanks.
; set ecx=3 6 00000004 8b0d[00000000] _start: mov ecx, [x] ; adds cl low byte of operand of instruction 8. on first ; iteration when ecx==3, add 3 48, resulting in 51, ; ascii code letter '3'. ; on second iteration add 2, resulting in 51+2 = 53 = '5'. ; on third iteration add 1, resulting in 53+1 = 54 = '6' 7 0000000a 000d[16000000] r: add byte [l+6], cl 8 00000010 c605[00000000]30 l: mov byte [x], 48 ; code prints whatever @ x if string. ; first character printed (since edx==1). ; explained above, on first iteration of loop x ; contain dword 0x00000033, on second 0x00000035 , on ; third 0x00000036. since we're printing 1 character (the ; least significant byte of dword) on each iteration, end ; printing characters 0x33, 0x35 , 0x36, correspond ; '3', '5' , '6' in ascii. 9 00000017 51 push ecx 10 00000018 b804000000 mov eax,4 11 0000001d bb01000000 mov ebx, 1 12 00000022 b9[00000000] mov ecx, x 13 00000027 ba01000000 mov edx,1 14 0000002c cd80 int 0x80 15 0000002e 59 pop ecx ; decrease ecx 1 , jump r if ecx!=0 16 0000002f e2d9 loop r,ecx
as segmentation fault; it's possible .text
section made read-only, , causes program crash when attempts modify @ instruction 7.
Comments
Post a Comment