Intel x86 Assembly Language amp Microarchitecture

Intel X86 Assembly Language Amp Microarchitecture-Free PDF

  • Date:17 Nov 2020
  • Views:6
  • Downloads:0
  • Pages:91
  • Size:1.31 MB

Share Pdf : Intel X86 Assembly Language Amp Microarchitecture

Download and Preview : Intel X86 Assembly Language Amp Microarchitecture


Report CopyRight/DMCA Form For : Intel X86 Assembly Language Amp Microarchitecture


Transcription:

Table of Contents, Chapter 1 Getting started with Intel x86 Assembly Language Microarchitecture 2. Examples 2,x86 Assembly Language 2,x86 Linux Hello World Example 3. Chapter 2 Assemblers 6,Examples 6,Microsoft Assembler MASM 6. Intel Assembler 6,AT T assembler as 7,Borland s Turbo Assembler TASM 7. GNU assembler gas 7,Netwide Assembler NASM 8,Yet Another Assembler YASM 9.
Chapter 3 Calling Conventions 10,Remarks 10,Resources 10. Examples 10,32 bit cdecl 10,Parameters 10,Return Value 11. Saved and Clobbered Registers 11,64 bit System V 11. Parameters 11,Return Value 11,Saved and Clobbered Registers 11. 32 bit stdcall 12,Parameters 12,Return Value 12,Saved and Clobbered Registers 12.
32 bit cdecl Dealing with Integers 12,As parameters 8 16 32 bits 12. As parameters 64 bits 12,As return value 13,32 bit cdecl Dealing with Floating Point 14. As parameters float double 14,As parameters long double 14. As return value 15,64 bit Windows 15,Parameters 15. Return Value 16,Saved and Clobbered Registers 16,Stack alignment 16.
32 bit cdecl Dealing with Structs 16,Padding 16,As parameters pass by reference 17. As parameters pass by value 17,As return value 17,Chapter 4 Control Flow 19. Examples 19,Unconditional jumps 19,Relative near jumps 19. Absolute indirect near jumps 19,Absolute far jumps 19. Absolute indirect far jumps 20,Missing jumps 20,Testing conditions 20.
Non destructive tests 21,Signed and unsigned tests 22. Conditional jumps 22,Synonyms and terminology 22,Equality 22. Greater than 23,Less than 24,Specific flags 24,One more conditional jump extra one 25. Test arithmetic relations 25,Unsigned integers 25,Signed integers 26. a label 26,Synonyms 27,Signed unsigned companion codes 27.
Chapter 5 Converting decimal strings to integers 28. Remarks 28,Examples 28,IA 32 assembly GAS cdecl calling convention 28. MS DOS TASM MASM function to read a 16 bit unsigned integer 29. Read a 16 bit unsigned integer from input 29,Return values 30. NASM porting 32, MS DOS TASM MASM function to print a 16 bit number in binary quaternary octal hex 32. Print a number in binary quaternary octal hexadecimal and a general power of two 32. Parameters 33,NASM porting 35,Extending the function 35. MS DOS TASM MASM function to print a 16 bit number in decimal 36. Print a 16 bit unsigned number in decimal 36,Parameters 36.
NASM porting 38,Chapter 6 Data Manipulation 39,Remarks 39. Examples 39,Using MOV to manipulate values 39,Chapter 7 Multiprocessor management 41. Parameters 41,Remarks 41,Examples 43,Wake up all the processors 43. Chapter 8 Optimization 50,Introduction 50,Remarks 50. Examples 50,Zeroing a register 50,Moving Carry flag into a register 50.
Background 50,Use sbb 51,Test a register for 0 51,Background 51. Use test 51,Linux system calls with less bloat 52,Multiply by 3 or 5 53. Background 53,Use lea 53,Chapter 9 Paging Virtual Addressing and Memory 54. Examples 54,Introduction 54,History 54,The first computers 54. Multi user multi processing 54,Example 54,Sophistication 54.
Solutions 54,Segmentation 55,Problems 55,Virtual addressing 55. Hardware and OS support 55,Paging features 55,Multiprocessing 56. Sparse Data 56,Virtual Memory 56,Paging decisions 57. How big should a Page be 57,How to optimise the usage of the Page Tables 57. 80386 Paging 58,High Level Design 58,Page Entry 59.
Page Directory Base Register PDBR 59,Page Faults 59. 80486 Paging 60,Pentium Paging 60,Address layout 60. Directory Entry layout 61,Physical Address Extension PAE 61. Introduction 61,More RAM 61,Page Size Extension PSE 62. PSE 32 and PSE 40 62,Chapter 10 Real vs Protected modes 64.
Examples 64,Real Mode 64,Protected Mode 65,Introduction 65. Segment Register 65,Global Local 65,Descriptor Table 65. Descriptor 66,True protection at last 66,Switching into Protected Mode 67. Unreal mode 68,Chapter 11 Register Fundamentals 71. Examples 71,16 bit Registers 71,32 bit registers 72.
8 bit Registers 72,Segment Registers 73,Segmentation 73. Original Segment Registers 73,Segment Size 73,More Segment Registers 74. 64 bit registers 74,Flags register 75,Condition Codes 75. Accessing FLAGS directly 76,Other Flags 76,80286 Flags 77. 80386 Flags 77,80486 Flags 77,Pentium Flags 78,Chapter 12 System Call Mechanisms 79.
Examples 79,BIOS calls 79,How to interact with the BIOS 79. Using BIOS calls with function select 79,Examples 79. How to write a character to the display 79, How to read a character from the keyboard blocking 79. How to read one or more sectors from an external drive using CHS addressing 80. How to read the system RTC Real Time Clock 80,How to read the system time from the RTC 80. How to read the system date from the RTC 81,How to get size of contiguous low memory 81.
How to reboot the computer 81,Error handling 81,References 81. Credits 82, You can share this PDF with anyone you feel could benefit from it downloaded the latest version. from intel x86 assembly language microarchitecture. It is an unofficial and free Intel x86 Assembly Language Microarchitecture ebook created for. educational purposes All the content is extracted from Stack Overflow Documentation which is. written by many hardworking individuals at Stack Overflow It is neither affiliated with Stack. Overflow nor official Intel x86 Assembly Language Microarchitecture. The content is released under Creative Commons BY SA and the list of contributors to each. chapter are provided in the credits section at the end of this book Images may be copyright of. their respective owners unless otherwise specified All trademarks and registered trademarks are. the property of their respective company owners, Use the content presented in this book at your own risk it is not guaranteed to be correct nor. accurate please send your feedback and corrections to info zzzprojects com. https riptutorial com 1,Chapter 1 Getting started with Intel x86. Assembly Language Microarchitecture, This section provides an overview of what x86 is and why a developer might want to use it.
It should also mention any large subjects within x86 and link out to the related topics Since the. Documentation for x86 is new you may need to create initial versions of those related topics. x86 Assembly Language, The family of x86 assembly languages represents decades of advances on the original Intel 8086. architecture In addition to there being several different dialects based on the assembler used. additional processor instructions registers and other features have been added over the years. while still remaining backwards compatible to the 16 bit assembly used in the 1980s. The first step to working with x86 assembly is to determine what the goal is If you are seeking to. write code within an operating system for example you will want to additionally determine. whether you will choose to use a stand alone assembler or built in inline assembly features of a. higher level language such as C If you wish to code down on the bare metal without an. operating system you simply need to install the assembler of your choice and understand how to. create binary code that can be turned into flash memory bootable image or otherwise be loaded. into memory at the appropriate location to begin execution. A very popular assembler that is well supported on a number of platforms is NASM Netwide. Assembler which can be obtained from http nasm us On the NASM site you can proceed to. download the latest release build for your platform. Both 32 bit and 64 bit versions of NASM are available for Windows NASM comes with a. convenient installer that can be used on your Windows host to install the assembler automatically. It may well be that NASM is already installed on your version of Linux To check execute. If the command is not found you will need to perform an install Unless you are doing something. that requires bleeding edge NASM features the best path is to use your built in package. management tool for your Linux distribution to install NASM For example under Debian derived. https riptutorial com 2, systems such as Ubuntu and others execute the following from a command prompt. sudo apt get install nasm,For RPM based systems you might try. sudo yum install nasm, Recent versions of OS X including Yosemite and El Capitan come with an older version of NASM. pre installed For example El Capitan has version 0 98 40 installed While this will likely work for. almost all normal purposes it is actually quite old At this writing NASM version 2 11 is released. and 2 12 has a number of release candidates available. You can obtain the NASM source code from the above link but unless you have a specific need to. install from source it is far simpler to download the binary package from the OS X release. directory and unzip it, Once unzipped it is strongly recommended that you not overwrite the system installed version of.
NASM Instead you might install it into usr local,user s password entered to become root. cd usr local bin,cp path to unzipped nasm files nasm. At this point NASM is in usr local bin but it is not in your path You should now add the. following line to the end of your profile,echo export PATH usr local bin PATH bash profile. This will prepend usr local bin to your path Executing nasm v at the command prompt should. now display the proper newer version,x86 Linux Hello World Example. This is a basic Hello World program in NASM assembly for 32 bit x86 Linux using system calls. directly without any libc function calls It s a lot to take in but over time it will become. understandable Lines starting with a semicolon are comments. If you don t already know low level Unix systems programming you might want to just write. functions in asm and call them from C or C programs Then you can just worry about learning. how to handle registers and memory without also learning the POSIX system call API and the ABI. for using it, This makes two system calls write 2 and exit 2 not the exit 3 libc wrapper that flushes stdio.
https riptutorial com 3, buffers and so on Technically exit calls sys exit group not sys exit but that only matters in. a multi threaded process See also syscalls 2 for documentation about system calls in general. and the difference between making them directly vs using the libc wrapper functions. In summary system calls are made by placing the args in the appropriate registers and the. system call number in eax then running an int 0x80 instruction See also What are the return. values of system calls in Assembly for more explanation of how the asm syscall interface is. documented with mostly C syntax, The syscall call numbers for the 32 bit ABI are in usr include i386 linux gnu asm unistd 32 h. same contents in usr include x86 64 linux gnu asm unistd 32 h. include sys syscall h will ultimately include the right file so you could run echo include. sys syscall h gcc E dM less to see the macro defs see this answer for more about. finding constants for asm in C headers, section text Executable code goes in the text section. global start The linker looks for this symbol to set the process entry point. so execution start here, a name followed by a colon defines a symbol The global start directive modifies it so. it s a global symbol not just one that we can CALL or JMP to from inside the asm. note that start isn t really a function You can t return from it and the kernel. passes argc argv and env differently than main would expect. write 1 msg len, Start by moving the arguments into registers where the kernel will look for them.
mov edx len 3rd arg goes in edx buffer length, mov ecx msg 2nd arg goes in ecx pointer to the buffer. Set output to stdout goes to your terminal or wherever you redirect or pipe. mov ebx 1 1st arg goes in ebx Unix file descriptor 1 stdout which is. normally connected to the terminal, mov eax 4 system call number from SYS write NR write from unistd 32 h. int 0x80 generate an interrupt activating the kernel s system call. handling code 64 bit code uses a different instruction different registers and different. call numbers,eax return value all other registers unchanged. Second exit the process There s nothing to return to so we can t use a ret. instruction like we could if this was main or any function with a caller. If we don t exit execution continues into whatever bytes are next in the memory page. typically leading to a segmentation fault because the padding 00 00 decodes to add. xor ebx ebx first arg exit status 0 will be truncated to 8 bits. Zeroing registers is a special case on x86 and mov ebx 0 would be less efficient. leaving out the zeroing of ebx would mean we exit 1 i e with an. error status since ebx still holds 1 from earlier,mov eax 1 put NR exit into eax. int 0x80 Execute the Linux function,section rodata Section for read only constants.
msg is a label and in this context doesn t need to be msg It could be on a. separate line,https riptutorial com 4, db Data Bytes assemble some literal bytes into the output file. from intel x86 assembly language microarchitecture It is an unofficial and free Intel x86 Assembly Language amp Microarchitecture ebook created for educational purposes All the content is extracted from Stack Overflow Documentation which is written by many hardworking individuals at Stack Overflow It is neither affiliated with Stack

Related Books