X86 Assembly Language II

X86 Assembly Language II

2/21/2017 x86 Assembly Language II CMSC 313 Sections 01, 02 Recap i386 Basic Architecture • Registers are storage units inside the CPU. • Registers are much faster than memory. • 8 General purpose registers in i386: – EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP – can access subparts of EAX, EBX, ECX and EDX via special names (e.g., EAXAX{AH,AL}) • The instruction pointer (EIP) points to (i.e., contains addr of) machine code to be executed next. • Typically, data moves from memory to registers, is processed, moves from registers back to memory. • Different addressing modes used. 2 UMBC, CMSC313, Richard Chang <[email protected]> BASIC EXECUTION ENVIRONMENT Basic Program Execution Registers Address Space* 232 -1 Eight 32-bit General-Purpose Registers Registers Six 16-bit Registers Segment Registers 32-bits EFLAGS Register 32-bits EIP (Instruction Pointer Register) FPU Registers Eight 80-bit Floating-Point Registers Data Registers 0 *The address space can be flat or segmented. Using 16-bits Control Register the physical address 16-bits Status Register extension mechanism, a physical address space of 16-bits Tag Register 236 1 can be addressed. Opcode Register (11-bits) 48-bits FPU Instruction Pointer Register 48-bits FPU Data (Operand) Pointer Register MMX Registers Eight 64-bit Registers MMX Registers SSE and SSE2 Registers 3 Eight 128-bit XMM Registers Registers 1 2/21/2017 General-Purpose Registers 31 16 15 8 7 0 16-bit 32-bit AH AL AX EAX BH BL BX EBX CH CL CX ECX DH DL DX EDX BP EBP SI ESI DI EDI SP ESP Figure 3-4. Alternate General-Purpose Register Names 4 • EAX—Accumulator for operands and results data. • EBX—Pointer to data in the DS segment. • ECX—Counter for string and loop operations. • EDX—I/O pointer. • ESI—Pointer to data in the segment pointed to by the DS register; source pointer for string operations.9 • EDI—Pointer to data (or destination) in the segment pointed to by the ES register; destination pointer for string operations. • ESP—Stack pointer (in the SS segment). • EBP—Pointer to data on the stack (in the SS segment). 5 toupper.asm • Use Linux system call to output prompt. • Use Linux system call to get user input. • Scan each character of user input and convert all lower case characters to upper case. • Learn how to: – work with 8-bit data – specify ASCII constant – compare values – do loop control • Use gdb to trace execution UMBC, CMSC313, Richard Chang <[email protected]> 6 2 2/21/2017 [Show source of toupper.asm] 7 GDB Debugger 8 Debugging Assembly Language Programs • Cannot just put print statements everywhere. • Use gdb to: – examine contents of registers – examine contents of memory – set breakpoints – single-step through program • READ THE GDB SUMMARY ONLINE! 9 UMBC, CMSC313, Richard Chang <[email protected]> 3 2/21/2017 Summary of gdb commands, p1 Command Example Description Run start program quit quit out of gdb cont continue execution after a break break [addr] break _start+5 sets a breakpoint delete [n] delete 4 removes nth breakpoint Delete removes all breakpoints info break lists all breakpoints list _start list a few lines of the source code around _start list 7 list 10 lines of the source code around line 7 list 7, 20 list lines 7 thru 20 of the source code 10 Summary of gdb commands, p2 Command Example Description Stepi or step execute next instruction stepi [n] stepi 4 execute next n instructions Nexti or next execute next instruction, stepping over function calls nexti [n] nexti 4 execute next n instructions, stepping over function calls where show where execution halted disas [addr] disas _start disassemble instructions at given address 11 Summary of gdb commands, p3 Command Example Description info registers dump contents of all registers print/d [expr] print/d $ecx print expression in decimal print/x [expr] print/x $ecx print expression in hex print/t [expr] print/t $ecx print expression in binary x/NFU [addr] x/12xw &msg Examine contents of memory in given format display [expr] display $eax automatically print the expression each time the program is halted info display show list of automatically displays undisplay [n] undisplay 1 remove an automatic display 12 4.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us