CS Basics 5) Programming in Assembly Language

Size: px
Start display at page:

Download "CS Basics 5) Programming in Assembly Language"

Transcription

1 CS Basics 5) Programming in Assembly Language Emmanuel Benoist Fall Term Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1

2 Programming in Assembly Language Minimal Program Move Flags Increment and decrement Conditional jumps Signed Values Structure of a program The Stack Interrupts Software Interrupts Hardware Interrupt System call 64-bit Conclusion Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

3 Minimal Program Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 3

4 Minimal Program For studying functionalities we need a sandbox To play with That do not do anything important That we can totaly destruct and rebuild Solution A program with no instruction, where we will try new features Only one thing is obligatory: a start point Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 4

5 Assembly Language Sandbox sandbox.asm section.data section.text global _start _start: nop ; Put your experiments between the two nops... nop ; Put your experiments between the two nops... Attention: This program does not terminate properly, it is just for testing purpose inside a debugger, Terminate the program manualy otherwise it will generate a core dump Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 5

6 Move Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 6

7 The MOV instruction Moves data from one location to another Syntax mov destination, source Is the most used command Move information from register to memory from memory to register from register to register But NOT form memory to memory Examples mov RAX, 42 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 7

8 Immediate Data Immediate addressing The data is built right into the machin instruction itself It is neither in a register, nor in a data item Intruction is in the instruction mov RAX, 42 mov RBX, Hello mov RCX, 0ABCDh Hello is stored in reverse order Because of little endian Size must be compatible cl is a 8-bit register 067EFh is 16 bits mov cl, 067EFh ; Instruction is not accepted by NASM Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 8

9 Move Register Data Register Addressing Name the register to work with mov EBP, ESI ; 32-bit mov BL, CH ; 8-bit add DX, AX ; 16-bit add ECX, EDX ; 32-bit add RAX, RBX ; 64-bit ADD instruction Adds the source and the destination The sum replaces whatever is in the destination Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 9

10 Example Test the following in a debugger mov ax,067feh mov bx, ax mov cl,bh mov ch,bl Set the breakpoint on the first instruction Single-step through the instructions watch carefully Halve registers (8-bit) are used for accessing RCX Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 10

11 Memory Data Is stored in the memory owned by the program Can be access using general purpose registers ;; Move to and from memory mov rbx, Snippet ;the address of the string in memory mov rcx, 3 ; the offset in the string mov ax, [rbx] ; Move 16 bits mov rax, [rbx+3] ; Move 64 bits mov eax, [rbx+rcx] ; Move 32 bits The [] operator Accesses the memory at the address inside the brackets [ebx] referes to memory whose address is stored in ebx [ebx+3] the memory whose address is the value of ebx plus 3 [ebx+ecx] the memory whose address is the sum of the values of ebx and ecx Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 11

12 Memory Data (Cont.) Size copied The size of data copied from the memory depends on the size of the register ax is 16-bit eax is 32-bit rax is 64-bit Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 12

13 Confusing Data and its Address Label are addresses EatMsg is the address of the string [EatMsg] is the content of the address For a 32-bit register, we transfer 4 bytes For a 64-bit register, we transfer 8 bytes section.data EatMsg db "Eat at Joe s" section.text global _start _start: nop ; Put your experiments between the two nops mov rcx, EatMsg ; copy the address mov rdx, [EatMsg] ; Copy 64 first bits of the message nop ; Put your experiments between the two nops Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 13

14 Flags Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 14

15 Flags The EFLAG register contains 32 bits: each one could be a flag Contains 18 Flags We present the most usefull ones Most of the flags represent a result of some kind OF: Overflow Flag When an arithmetic operation on a signed integer quantity becomes too large Is generally used as a carry flag in signed arithmetic DF: Direction Flag It tells the CPU something you want Tells the direction you want for string instruction If DF = 1 string instructions proceed from high memory toward low memory if DF=0 string instructions proceed from low memory toward high memory. Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 15

16 Flags (Cont.) IF: Interrupt enable flag The CPU can set it You can set it using STI (set IF) and CLI (clear IF) When IF is set, interrupts are enabled and may occur when requested When IF is cleared interrupts are ignored TF: Trap Flag allows debuggers to manage single-stepping it forces the CPU to execute only a single instruction SF: Sign Flag becomes set, when the result of an operation forces the operand to become negative means: the first bit becomes 1 during the operation Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 16

17 Flags (Cont.) ZF: Zero Flag is set when the result of an operation becomes zero. PF: Parity Flag Familiar with serial data communication Indicates if the number of ones in the low-order byte is even or odd CF: Carry Flag is used in unsigned arithmetic operations if the result carries out a bit from the operand Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 17

18 Increment and decrement Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 18

19 Increment and decrement INC: Increment Adds one to its operand DEC: decrement Substract one from its operand Example mov eax, 0FFFFFFFFh mov ebx, 02Dh dec ebx inc eax ebx becomes 2Ch eax becomes 0 Carry Flag is not affected by INC The last instruction changes Flags PF (parity), AF (Auxillary), ZF (zero), IF (interrupt) are set Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 19

20 Conditional jumps Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 20

21 Conditional jumps Most of the flags have a conditional jump JNZ : Jump if not zero If ZF is clear, nothing is done If ZF is set, execution travels to a new destination Example: First loop ;; A first loop mov eax, 5 DoMore: dec eax jnz DoMore As long as eax is not zero, loops to DoMore Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 21

22 Kangaroo Kangaroo.asm section.data Snippet db "KANGAROO" section.text global _start _start: nop ; Put your experiments between the two nops... mov ebx,snippet mov eax,8 DoMore: add byte [ebx],32 inc ebx dec eax jnz DoMore ; Put your experiments between the two nops... nop Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 22

23 Kangaroo (Cont.) The string KANGAROO is stored in memory It receives a label Snippet eax is a counter that is decremented ebx is incremented from the Snippet label, to the end of the string Letters are changed to lowercase One substracts 32 to all the letters We can check in the memory Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 23

24 Signed Values Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 24

25 Signed Values x86 architecture uses two s complement for signed values -42 is denoted in a 8 bit register on a 32-bit registers H-42 on a 64-bit register H -42 Let us try the following code mov eax, 5 DoMore: dec eax jmp DoMore Jump is inconditional (it is always done) Eax becomes 0FFFFFFFFh (-1) 0FFFFFFFEh (-2) 0FFFFFFFDh (-3) 0FFFFFFFCh (-3) Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 25

26 NEG instruction NEG generates a negative number Transforms a positive number into a negative one. Example ;; We generate a negative number mov eax, 42 neg eax add eax, 42 We increment the last positive number and get a negative one ;; we increment the last positive number ;; changes SF (sign flag) mov ebx, 07FFFFFFFh inc ebx ; sets the CF PF AF SF OF Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 26

27 Move signed numbers Moving signed numbers MOV does not work if the size changes The number is copied as a number The new number is not a valid negative number Solution: MOVSX Move with Sign extension mov ax, -42 mov ebx, eax ; value is not -42 mov ax, -42 movsx ebx, ax ; value remains -42 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 27

28 Multiplication MUL and DIV handle unsigned calculation MUL multiplies two operands But the result is larger than the operand if operands are 64-bit, result can be 128-bit need two registers for the result IMUL and IDIV handle signed calculation Pretty much the same functionality with signed numbers Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 28

29 MUL implicit operands Explicit operand One factor Implicit operand One factor (AL, AX, EAX, RAX depending on the size of the explicit operand) Product (AX, DX and AX, EDX (high order bytes) and EAX (low order bytes), RDX and RAX respectively) Example mov eax, 447 mov ebx, 1739 mul ebx ;values in eax and edx are set mov eax, 56 mov ebx, 67 neg ebx imul ebx Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 29

30 Structure of a program Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 30

31 Structure Initial comment block Author, date, version, description Data section Contains all initialized data Data must have a value Similar to constants BSS section Contains unitialized data Just placeholders Place will be reserved in the memory Text session Contains the code need a global label start to be executed Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 31

32 Example ; Executable name : EATSYSCALL ; Version : 1.0 ; Created date : 1/7/2009 ; Last update : 2/18/2009 ; Author : Jeff Duntemann ; Description : A simple program in assembly for Linux, using NASM 2.05, ; demonstrating the use of Linux INT 80H syscalls to display text. ; ; Build using these commands: ; nasm f elf g F stabs eatsyscall.asm ; ld o eatsyscall eatsyscall.o ; SECTION.data ; Section containing initialised data EatMsg: db Eat at Joe s!,10 EatLen: equ $ EatMsg SECTION.bss ; Section containing uninitialized data SECTION.text ; Section containing code global start ; Linker needs this to find the entry point! start: nop ; This no op keeps gdb happy... mov eax,4 ; Specify sys write call mov ebx,1 ; Specify File Descriptor 1: Standard Output mov ecx,eatmsg ; Pass offset of the message mov edx,eatlen ; Pass the length of the message int 80H ; Make kernel call MOV eax,1 ; Code for Exit Syscall mov ebx,0 ; Return a code of zero int 80H ; Make kernel call Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 32

33 The.text Section Labels must begin with a letter or an underscore must be followed by a semicolon when they are defined are case sensitive Are used as targets for jumps label start must be present and declared global in any Linux program Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 33

34 Variables For initialized Data In the Data section data definition directive Example MyByte db 07h ; 8 bits in size MyWord dw 0FFFFh : 16 bits in size MyDouble dd 0B h ; 32 bits in size MyQuad dq 0B h ; 64 bits Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 34

35 String Variables Example eatmsg: db "Eat at Joes s!",10 Is a label (address) of information in memory Contains bytes (db) Strings can be concatenated Eat at Joes s!,10 End of Line, EOL (0Ah / 10), is added at the end of the string TwoLineMsg: db "Eat at Joe s...",10,"... Ten million flies can t ALL be wrong!",10 When displayed, produces two lines Eat at Joe s Ten million flies can t ALL be wrong! Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 35

36 Derive String Length Interesting: EatLen: equ $-EatMsg EQU stands for equate Associate a value with a label Like a named constant FieldWidth equ 10 The following two lines are equal mov eax,10 mov eax, FieldWidth Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 36

37 Derive String length (Cont.) We need length of the string We could hard code it EatMsg db "Eat at Joe s!",10 EatLen equ 14 But what appens if we change the string We have to change the length : VERY error prone Use the here token: the $ sign marks the spot where NASM is in the intermediate file $ and EatMsg are both locations (addresses in memory) One can compute the difference: where do the string start and finishes EatMsg: db "Eat at Joe s!",10 EatLen: equ $-EatMsg Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 37

38 The Stack Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 38

39 The Stack Is used to store information temporarly Store the status of a program while doing something else LIFO Last In - First Out Push : add on top of the stack Pop: remove from the top of the stack Pez Dispenser The new candy are eaten first The old candies remain at the bottom Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 39

40 The Stack Push four items onto the stack: Pop two items off the stack: Push three items onto the stack: Top of the Stack Top of the Stack Top of the Stack Top of the Stack Figure 8-1: The stack Stacking Things Upside Down Making things a little trickier to visualize is the fact that the x86 stack is basically upside-down. If you picture a region of memory with the lowest Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 40

41 Stack in Memory Stack starts at the top of memory Start at the higher memory Go down in the free memory Opposite to the rest text section data section bss section are stored at the bottom of the memory C program allocate dynamically the free memory On the fly while it works Inside the heap Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 41

42 The Stack in Memory Highest memory addresses The Stack ESP moves up and down as items are pushed onto or popped from the stack ESP always points to the last item pushed onto the stack Free Memory.bss section (Uninitialized data items).data section (Initialized data items) Lowest memory addresses.text section (Program code) Figure 8-2: The stack in program memory Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 42

43 Push instructions Add information on top of the stack PUSH a register or memory value PUSHF push the Flags register examples push ax ; Push the AX register ; push ebx ; push the EAX register not supported in 64-bit mode push rax ; Push the RAX register push word[rbx] ; Push the word stored at bx push qword[rdx] ; Push the double word stored at edx push rdi ; Push the RDI register pushf ; Push the flags on the stack Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 43

44 Pop instructions Retrieve information out of the stack Removes the information from the stack and transfers it It is up to you to know what information is stored on the stack Instructions POP, POPF (for flags) Examples popf ;Pop the flags out of the stack pop CX ; Pop the top 2 bytes from the stack into CX pop RSI ; Pop the top 16 bytes from the stack into RSI pop qword[rbx] ; Pop the top 8 bytes from the stack into the memory at EBX pop qword[vars1] ; Pop the top 8 bytes from the stack into the memory at var1 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 44

45 POP BX ;..and pop it immediately into BX How the stack works Not all bits of EFlags may be changed with POPFD. BitsVMandRFarenot affected by popping a value off the stack into EFlags. AX = 01234h BX = 04BA7h CX = 0FF17h DX = 0000 PUSH AX PUSH BX PUSH CX POP DX High Memory SP B B B A7 SP A7 A7 SP FF 17 SP Low Memory Figure 8-3: How the stack works DX now contains 0FF17h Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 45

46 Interrupts Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 46

47 Software Interrupts Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 47

48 Interrupts Used to communicate with the Linux Kernel Not authorized to access memory where Kernel instructions are Protected mode Need a way to execute kernel instructions Interrupts Interrupt vector table Placed at the first 1024 bytes of memory of any x86 computer Each vector has a number from 0 to 255 Each vector contains the address (including offset and segment) of kernel functions Addresses can be dynamically allocated (regarding where the kernel is executed) Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 48

49 The interrupt accurate addresses. vector table parts, and when you upgrade to a new version of Linux, that new version will fill the appropriate slots in the interrupt vector table with upgraded and h Vector Ch Vector h Vector h Vector 0 Figure 8-4: The interrupt vector table The lowest location in x86 memory h Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 49

50 Interrupt 80h = the dispatcher An interrupt number correspond to one function It remains the same, always 80h corresponds to the dispatcher The INT instruction Is used in the program CPU goes to the interrupt vector table Fetches the address from slot 80h Jumps execution to that address The dispacher picks up the execution and performs the service Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 50

51 the dispatcher which service you need, which you do by placing the service s number register EAX. The dispatcher may require other information as well, Riding an interrupt vector into Linux and will expect you to provide that information in the correct place almost always in various registers before it begins its job. The INT80h instruction first pushes the address of the instruction after it onto the stack... The Stack Return Address Your Code...and then jumps to whatever address is stored in vector 80h. INT 80h (Next Instruction) User Space Kernel Space Linux The address at vector 80h takes execution into the Linux system call dispatcher Dispatcher Vector Table Vector 80h Figure 8-5: Riding an interrupt vector into Linux Look at the following lines of code from eatsyscall.asm: Berner Fachhochschule Haute cole spcialise mov eax,4 bernoise ; Berne Specify University sys_write syscall of Applied Sciences 51

52 The dispatcher Controles access to 200 individual routines Tell the dispacher which service you need Place service number in register RAX The dispatcher may require other information as well Most allways in various registers Example mov eax,4 ; Specify sys_write call mov ebx,1 ; Specify File Descriptor 1: Standard Output mov ecx,eatmsg ; Pass offset of the message mov edx,eatlen ; Pass the length of the message int 80H ; Make kernel call Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 52

53 File descriptors Standard Input stdin File descriptor 0 Standard Output stdout FIle descriptor 1 Standard Error stderr File descriptor 2 Other files Generate a new file descriptor Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 53

54 Return to your program When the routine is finished Linux goes back to your program Has to know where to go back Stack The instruction number is stored on the stack when the interrupt is called When it is finished: the address is poped from the stack And inserted back in the instruction pointer (RIP) It is the address of the next instruction to be executed. Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 54

55 Exiting this way is not just a nicety. Every program you write must exit Berner Fachhochschule Haute cole by spcialise makingbernoise a call to sys_exit Berne University through the of kernel Applied services Sciences dispatcher. If a 55 Returning home from an interrupt The Stack Return Address Your Code INT 80h (Next Instruction) Linux Dispatcher IRET...and then jumps to the instruction at that address, which is the one immediately after the INT 80h. The IRET instruction pops the return address off the stack... Vector Table Vector 80h Figure 8-6: Returning home from an interrupt

56 Exiting the program Call the dispatcher INT 80 instruction Parameters Routine is number 1 in RAX Value 0 is stored in RBX (everything went well) Or something else Example MOV eax,1 mov ebx,0 int 80H ; Code for Exit Syscall ; Return a code of zero ; Make kernel call Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 56

57 Hardware Interrupt Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 57

58 Hardware Interrupt CPU mechanism to pay attention to the world PC circuits can send signals to the CPU Keyboard, network, disk, USB,... CPU can interrupt its work to treat the message Harware interrupts are also addresses Each interrupt has a number The table links together number and address of the instructions Called: ISR Interrupt Service Routine Difference hardware vs software interrupt Harware interrupt is trigered by something outside your code Software interrupt is trigered by something inside your code Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 58

59 System call 64-bit Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 59

60 System Call System Call replace software interrupt Call to system functions can be done using interrupt 80h They can also be done using syscall Call functions reserved to the system Exit the program Print something on the standard output (or error output) Print something in a file Manipulate files Read chars from the standard input... Parameters RAX : the function number 0 : sys read (read input or file) 1 : sys wirte (write ouput or file) 2 : sys open (for a file) 3 : sys close (idem) : sys exit Other parameters: RDI, RSI, RDX, R10, R8, R9 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 60

61 System Call: Examples Displaying a string RAX : 1 = sys write RDI : 1 = Standard output RSI : address of the string to be written RDX : length of the string (number of bytes) mov rax,1 ; Code for Sys_write call mov rdi, 1 ; Specify File Descriptor 1: Standard Output mov rsi, EatMsg ; Pass offset of the message mov rdx, EatLen ; Pass the length of the message syscall ; Make kernel call Exit program RAX : 60 = sys exit RDI : 0 = returned value (0 means OK) mov rax, 60 ; Code for exit mov rdi, 0 ; Return a code of zero syscall ; Make kernel call Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 61

62 Eat Message using 64-bit syscalls SECTION.data ; Section containing initialised data EatMsg: db Eat at Joe s!,10 EatLen: equ $ EatMsg SECTION.bss ; Section containing uninitialized data SECTION.text ; Section containing code global start ; Linker needs this to find the entry point! start: nop ; This no op keeps gdb happy... mov rax,1 ; Code for Sys write call mov rdi, 1 ; Specify File Descriptor 1: Standard Output mov rsi, EatMsg ; Pass offset of the message mov rdx, EatLen ; Pass the length of the message syscall ; Make kernel call mov rax, 60 ; Code for exit mov rdi, 0 ; Return a code of zero syscall ; Make kernel call Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 62

63 Conclusion Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 63

64 Conclusion Structure of a program Initialisation of the data in memory Placeholders to reserve place in memory Programm Stack Used to store temporary information Useful for calling an interrupt, to restore the environment Will be used to call functions in our code Interrupt Possibility to access Kernel routines Used also to react to external stimuli Mainly based on a vector containing the addresses of default functions. Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 64

65 Bibliography This course corresponds to the chapters 7 and 8 of the course book: Assembly Language Step by Step (3rd Edition) Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 65

CS Basics 8) Strings. Emmanuel Benoist. Fall Term Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1

CS Basics 8) Strings. Emmanuel Benoist. Fall Term Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1 CS Basics 8) Strings Emmanuel Benoist Fall Term 2016-17 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1 Strings Loops on Strings Strings in assembly STOre String

More information

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

More information

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86 Lecture 15 Intel Manual, Vol. 1, Chapter 3 Hampden-Sydney College Fri, Mar 6, 2009 Outline 1 2 Overview See the reference IA-32 Intel Software Developer s Manual Volume 1: Basic, Chapter 3. Instructions

More information

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2011 Assembly Language Lab # 2 Assembly Language Fundamentals Assembly Language Lab # 2 Assembly Language Fundamentals

More information

Module 3 Instruction Set Architecture (ISA)

Module 3 Instruction Set Architecture (ISA) Module 3 Instruction Set Architecture (ISA) I S A L E V E L E L E M E N T S O F I N S T R U C T I O N S I N S T R U C T I O N S T Y P E S N U M B E R O F A D D R E S S E S R E G I S T E R S T Y P E S O

More information

The x86 Architecture

The x86 Architecture The x86 Architecture Lecture 24 Intel Manual, Vol. 1, Chapter 3 Robb T. Koether Hampden-Sydney College Fri, Mar 20, 2015 Robb T. Koether (Hampden-Sydney College) The x86 Architecture Fri, Mar 20, 2015

More information

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth Registers Ray Seyfarth September 8, 2011 Outline 1 Register basics 2 Moving a constant into a register 3 Moving a value from memory into a register 4 Moving values from a register into memory 5 Moving

More information

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY BACKGROUND 8086 CPU has 8 general purpose registers listed below: AX - the accumulator register (divided into AH / AL): 1. Generates shortest machine code 2. Arithmetic, logic and data transfer 3. One

More information

x86 Assembly Tutorial COS 318: Fall 2017

x86 Assembly Tutorial COS 318: Fall 2017 x86 Assembly Tutorial COS 318: Fall 2017 Project 1 Schedule Design Review: Monday 9/25 Sign up for 10-min slot from 3:00pm to 7:00pm Complete set up and answer posted questions (Official) Precept: Monday

More information

Computer Architecture and System Programming Laboratory. TA Session 3

Computer Architecture and System Programming Laboratory. TA Session 3 Computer Architecture and System Programming Laboratory TA Session 3 Stack - LIFO word-size data structure STACK is temporary storage memory area register points on top of stack (by default, it is highest

More information

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated CNIT 127: Exploit Development Ch 1: Before you begin Updated 1-14-16 Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend, such as Denial

More information

Computer Architecture and Assembly Language. Practical Session 3

Computer Architecture and Assembly Language. Practical Session 3 Computer Architecture and Assembly Language Practical Session 3 Advanced Instructions division DIV r/m - unsigned integer division IDIV r/m - signed integer division Dividend Divisor Quotient Remainder

More information

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM EXPERIMENT WRITE UP AIM: Assembly language program for 16 bit BCD addition LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM TOOLS/SOFTWARE

More information

Code segment Stack segment

Code segment Stack segment Registers Most of the registers contain data/instruction offsets within 64 KB memory segment. There are four different 64 KB segments for instructions, stack, data and extra data. To specify where in 1

More information

Basic Execution Environment

Basic Execution Environment Basic Execution Environment 3 CHAPTER 3 BASIC EXECUTION ENVIRONMENT This chapter describes the basic execution environment of an Intel Architecture processor as seen by assembly-language programmers.

More information

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1 Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD 21252 rkarne@towson.edu 11/12/2014 Slide 1 Intel x86 Aseembly Language Assembly Language Assembly Language

More information

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

X86 Addressing Modes Chapter 3 Review: Instructions to Recognize X86 Addressing Modes Chapter 3" Review: Instructions to Recognize" 1 Arithmetic Instructions (1)! Two Operand Instructions" ADD Dest, Src Dest = Dest + Src SUB Dest, Src Dest = Dest - Src MUL Dest, Src

More information

Intel 8086: Instruction Set

Intel 8086: Instruction Set IUST-EE (Chapter 6) Intel 8086: Instruction Set 1 Outline Instruction Set Data Transfer Instructions Arithmetic Instructions Bit Manipulation Instructions String Instructions Unconditional Transfer Instruction

More information

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide Lecture 9 INC and DEC Arithmetic Operations Overflow Multiply and Divide INC adds one to a single operand DEC decrements one from a single operand INC destination DEC destination where destination can

More information

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Marking Scheme. Examination Paper. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam Second Semester Date: 12/06/2017 Section 1 Weighting 40% of

More information

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans. INSTRUCTOR: ABDULMUTTALIB A H ALDOURI Conditional Jump Cond Unsigned Signed = JE : Jump Equal JE : Jump Equal ZF = 1 JZ : Jump Zero JZ : Jump Zero ZF = 1 JNZ : Jump Not Zero JNZ : Jump Not Zero ZF = 0

More information

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad Introduction to MS-DOS Debugger DEBUG In this laboratory, we will use DEBUG program and learn how to: 1. Examine and modify the contents of the 8086 s internal registers, and dedicated parts of the memory

More information

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Lab # 7 Procedures and the Stack April, 2014 1 Assembly Language LAB Runtime Stack and Stack

More information

Computer Architecture and Assembly Language. Practical Session 5

Computer Architecture and Assembly Language. Practical Session 5 Computer Architecture and Assembly Language Practical Session 5 Addressing Mode - "memory address calculation mode" An addressing mode specifies how to calculate the effective memory address of an operand.

More information

X86-NASM STANDARD COMMANDS. Comment your code with a semicolon (;)! The assembler won t read anything after it.

X86-NASM STANDARD COMMANDS. Comment your code with a semicolon (;)! The assembler won t read anything after it. X86-NASM STANDARD COMMANDS Comment your code with a semicolon (;)! The assembler won t read anything after it. Move mov ax,bx ; ax = bx Use this command when you want to move a value around. You can also

More information

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10] The following pages contain references for use during the exam: tables containing the x86 instruction set (covered so far) and condition codes. You do not need to submit these pages when you finish your

More information

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313) Philadelphia University Faculty of Engineering Marking Scheme Examination Paper Department of CE Module: Microprocessors (630313) Final Exam Second Semester Date: 02/06/2018 Section 1 Weighting 40% of

More information

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to: Introduction Efficient software development for the microprocessor requires a complete familiarity with the addressing modes employed by each instruction. This chapter explains the operation of the stack

More information

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs CSC 2400: Computer Systems Towards the Hardware: Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32)

More information

Introduction to IA-32. Jo, Heeseung

Introduction to IA-32. Jo, Heeseung Introduction to IA-32 Jo, Heeseung IA-32 Processors Evolutionary design Starting in 1978 with 8086 Added more features as time goes on Still support old features, although obsolete Totally dominate computer

More information

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017) Microprocessor and Assembly Language Week-5 System Programming, BCS 6th, IBMS (2017) High Speed Memory Registers CPU store data temporarily in these location CPU process, store and transfer data from one

More information

INTRODUCTION TO IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung INTRODUCTION TO IA-32 Jo, Heeseung IA-32 PROCESSORS Evolutionary design Starting in 1978 with 8086 Added more features as time goes on Still support old features, although obsolete Totally dominate computer

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer About the Tutorial Assembly language is a low-level programming language for a computer or other programmable device specific to a particular computer architecture in contrast to most high-level programming

More information

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections x86 Assembler Computer Systems: Sections 3.1-3.5 Disclaimer I am not an x86 assembler expert. I have never written an x86 assembler program. (I am proficient in IBM S/360 Assembler and LC3 Assembler.)

More information

CSC 8400: Computer Systems. Machine-Level Representation of Programs

CSC 8400: Computer Systems. Machine-Level Representation of Programs CSC 8400: Computer Systems Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 Compilation Stages

More information

Instruction Set Architecture (ISA) Data Types

Instruction Set Architecture (ISA) Data Types Instruction Set Architecture (ISA) Data Types Computer Systems: Section 4.1 Suppose you built a computer What Building Blocks would you use? Arithmetic Logic Unit (ALU) OP1 OP2 OPERATION ALU RES Full Adder

More information

Complex Instruction Set Computer (CISC)

Complex Instruction Set Computer (CISC) Introduction ti to IA-32 IA-32 Processors Evolutionary design Starting in 1978 with 886 Added more features as time goes on Still support old features, although obsolete Totally dominate computer market

More information

ASSEMBLY - QUICK GUIDE ASSEMBLY - INTRODUCTION

ASSEMBLY - QUICK GUIDE ASSEMBLY - INTRODUCTION ASSEMBLY - QUICK GUIDE http://www.tutorialspoint.com/assembly_programming/assembly_quick_guide.htm Copyright tutorialspoint.com What is Assembly Language? ASSEMBLY - INTRODUCTION Each personal computer

More information

Machine and Assembly Language Principles

Machine and Assembly Language Principles Machine and Assembly Language Principles Assembly language instruction is synonymous with a machine instruction. Therefore, need to understand machine instructions and on what they operate - the architecture.

More information

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013) SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013) UNIT I THE 8086 MICROPROCESSOR PART A (2 MARKS) 1. What are the functional

More information

3.1 DATA MOVEMENT INSTRUCTIONS 45

3.1 DATA MOVEMENT INSTRUCTIONS 45 3.1.1 General-Purpose Data Movement s 45 3.1.2 Stack Manipulation... 46 3.1.3 Type Conversion... 48 3.2.1 Addition and Subtraction... 51 3.1 DATA MOVEMENT INSTRUCTIONS 45 MOV (Move) transfers a byte, word,

More information

CC411: Introduction To Microprocessors

CC411: Introduction To Microprocessors CC411: Introduction To Microprocessors OBJECTIVES this chapter enables the student to: Describe the Intel family of microprocessors from 8085 to Pentium. In terms of bus size, physical memory & special

More information

EC 333 Microprocessor and Interfacing Techniques (3+1)

EC 333 Microprocessor and Interfacing Techniques (3+1) EC 333 Microprocessor and Interfacing Techniques (3+1) Lecture 6 8086/88 Microprocessor Programming (Arithmetic Instructions) Dr Hashim Ali Fall 2018 Department of Computer Science and Engineering HITEC

More information

UNIT 2 PROCESSORS ORGANIZATION CONT.

UNIT 2 PROCESSORS ORGANIZATION CONT. UNIT 2 PROCESSORS ORGANIZATION CONT. Types of Operand Addresses Numbers Integer/floating point Characters ASCII etc. Logical Data Bits or flags x86 Data Types Operands in 8 bit -Byte 16 bit- word 32 bit-

More information

Lecture 2 Assembly Language

Lecture 2 Assembly Language Lecture 2 Assembly Language Computer and Network Security 9th of October 2017 Computer Science and Engineering Department CSE Dep, ACS, UPB Lecture 2, Assembly Language 1/37 Recap: Explorations Tools assembly

More information

CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE351 Spring 2018, Midterm Exam April 27, 2018 CSE351 Spring 2018, Midterm Exam April 27, 2018 Please do not turn the page until 11:30. Last Name: First Name: Student ID Number: Name of person to your left: Name of person to your right: Signature indicating:

More information

Computer Architecture and System Programming Laboratory. TA Session 5

Computer Architecture and System Programming Laboratory. TA Session 5 Computer Architecture and System Programming Laboratory TA Session 5 Addressing Mode specifies how to calculate effective memory address of an operand x86 64-bit addressing mode rule: up to two of the

More information

The Instruction Set. Chapter 5

The Instruction Set. Chapter 5 The Instruction Set Architecture Level(ISA) Chapter 5 1 ISA Level The ISA level l is the interface between the compilers and the hardware. (ISA level code is what a compiler outputs) 2 Memory Models An

More information

Arithmetic and Logic Instructions And Programs

Arithmetic and Logic Instructions And Programs Dec Hex Bin 3 3 00000011 ORG ; FOUR Arithmetic and Logic Instructions And Programs OBJECTIVES this chapter enables the student to: Demonstrate how 8-bit and 16-bit unsigned numbers are added in the x86.

More information

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Assembly Language Each statement in an assembly language program consists of four parts or fields. Chapter 3: Addressing Modes Assembly Language Each statement in an assembly language program consists of four parts or fields. The leftmost field is called the label. - used to identify the name of a memory

More information

Come and join us at WebLyceum

Come and join us at WebLyceum Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 4 LAST TIME Enhanced our processor design in several ways Added branching support Allows programs where work is proportional to the input values

More information

How Software Executes

How Software Executes How Software Executes CS-576 Systems Security Instructor: Georgios Portokalidis Overview Introduction Anatomy of a program Basic assembly Anatomy of function calls (and returns) Memory Safety Programming

More information

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut dthiebaut@smith.edu Homework Solutions Outline Review Hexdump Pentium Data Registers 32-bit, 16-bit and 8-bit quantities (registers

More information

ORG ; TWO. Assembly Language Programming

ORG ; TWO. Assembly Language Programming Dec 2 Hex 2 Bin 00000010 ORG ; TWO Assembly Language Programming OBJECTIVES this chapter enables the student to: Explain the difference between Assembly language instructions and pseudo-instructions. Identify

More information

Credits and Disclaimers

Credits and Disclaimers Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 3 nd Edition by Bryant and O'Hallaron

More information

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU) Part 2 Computer Processors Processors The Brains of the Box Computer Processors Components of a Processor The Central Processing Unit (CPU) is the most complex part of a computer In fact, it is the computer

More information

SOEN228, Winter Revision 1.2 Date: October 25,

SOEN228, Winter Revision 1.2 Date: October 25, SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003 1 Contents Flags Mnemonics Basic I/O Exercises Overview of sample programs 2 Flag Register The flag register stores the condition flags that retain

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures Computer Systems: Section 4.1 Suppose you built a computer What Building Blocks would you use? Arithmetic Logic Unit (ALU) OP1 OP2 OPERATION ALU RES ALU + Registers R0: 0x0000

More information

EEM336 Microprocessors I. Addressing Modes

EEM336 Microprocessors I. Addressing Modes EEM336 Microprocessors I Addressing Modes Introduction Efficient software development for the microprocessor requires a complete familiarity with the addressing modes employed by each instruction. This

More information

Program Exploitation Intro

Program Exploitation Intro Program Exploitation Intro x86 Assembly 04//2018 Security 1 Univeristà Ca Foscari, Venezia What is Program Exploitation "Making a program do something unexpected and not planned" The right bugs can be

More information

8086 INTERNAL ARCHITECTURE

8086 INTERNAL ARCHITECTURE 8086 INTERNAL ARCHITECTURE Segment 2 Intel 8086 Microprocessor The 8086 CPU is divided into two independent functional parts: a) The Bus interface unit (BIU) b) Execution Unit (EU) Dividing the work between

More information

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017 CS 31: Intro to Systems ISAs and Assembly Martin Gagné Swarthmore College February 7, 2017 ANNOUNCEMENT All labs will meet in SCI 252 (the robot lab) tomorrow. Overview How to directly interact with hardware

More information

Summary: Direct Code Generation

Summary: Direct Code Generation Summary: Direct Code Generation 1 Direct Code Generation Code generation involves the generation of the target representation (object code) from the annotated parse tree (or Abstract Syntactic Tree, AST)

More information

Lab 3. The Art of Assembly Language (II)

Lab 3. The Art of Assembly Language (II) Lab. The Art of Assembly Language (II) Dan Bruce, David Clark and Héctor D. Menéndez Department of Computer Science University College London October 2, 2017 License Creative Commons Share Alike Modified

More information

Computer Systems Lecture 9

Computer Systems Lecture 9 Computer Systems Lecture 9 CPU Registers in x86 CPU status flags EFLAG: The Flag register holds the CPU status flags The status flags are separate bits in EFLAG where information on important conditions

More information

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP. Procedures: CALL: Pushes the address of the instruction following the CALL instruction onto the stack. RET: Pops the address. SUM PROC NEAR USES BX CX DX ADD AX, BX ADD AX, CX MOV AX, DX RET SUM ENDP NEAR

More information

Chapter Four Instructions Set

Chapter Four Instructions Set Chapter Four Instructions set Instructions set 8086 has 117 instructions, these instructions divided into 6 groups: 1. Data transfer instructions 2. Arithmetic instructions 3. Logic instructions 4. Shift

More information

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil Microprocessor By Mrs. R.P.Chaudhari Mrs.P.S.Patil Chapter 1 Basics of Microprocessor CO-Draw Architecture Of 8085 Salient Features of 8085 It is a 8 bit microprocessor. It is manufactured with N-MOS technology.

More information

Rev101. spritzers - CTF team. spritz.math.unipd.it/spritzers.html

Rev101. spritzers - CTF team. spritz.math.unipd.it/spritzers.html Rev101 spritzers - CTF team spritz.math.unipd.it/spritzers.html Disclaimer All information presented here has the only purpose of teaching how reverse engineering works. Use your mad skillz only in CTFs

More information

Chapter 3: Addressing Modes

Chapter 3: Addressing Modes Chapter 3: Addressing Modes Chapter 3 Addressing Modes Note: Adapted from (Author Slides) Instructor: Prof. Dr. Khalid A. Darabkh 2 Introduction Efficient software development for the microprocessor requires

More information

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Machine-level Representation of Programs Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Program? 짬뽕라면 준비시간 :10 분, 조리시간 :10 분 재료라면 1개, 스프 1봉지, 오징어

More information

Assembly Language: IA-32 Instructions

Assembly Language: IA-32 Instructions Assembly Language: IA-32 Instructions 1 Goals of this Lecture Help you learn how to: Manipulate data of various sizes Leverage more sophisticated addressing modes Use condition codes and jumps to change

More information

ADVANCE MICROPROCESSOR & INTERFACING

ADVANCE MICROPROCESSOR & INTERFACING VENUS INTERNATIONAL COLLEGE OF TECHNOLOGY Gandhinagar Department of Computer Enggineering ADVANCE MICROPROCESSOR & INTERFACING Name : Enroll no. : Class Year : 2014-15 : 5 th SEM C.E. VENUS INTERNATIONAL

More information

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998 Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998 Assembler Syntax Everything looks like this: label: instruction dest,src instruction label Comments: comment $ This is a comment

More information

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth Functions Ray Seyfarth August 4, 2011 Functions We will write C compatible function C++ can also call C functions using extern "C" {...} It is generally not sensible to write complete assembly programs

More information

Q1: Multiple choice / 20 Q2: Protected mode memory accesses

Q1: Multiple choice / 20 Q2: Protected mode memory accesses 16.317: Microprocessor-Based Systems I Summer 2012 Exam 2 August 1, 2012 Name: ID #: For this exam, you may use a calculator and one 8.5 x 11 double-sided page of notes. All other electronic devices (e.g.,

More information

ALT-Assembly Language Tutorial

ALT-Assembly Language Tutorial ALT-Assembly Language Tutorial ASSEMBLY LANGUAGE TUTORIAL Let s Learn in New Look SHAIK BILAL AHMED i A B O U T T H E T U TO R I A L Assembly Programming Tutorial Assembly language is a low-level programming

More information

EEM336 Microprocessors I. Data Movement Instructions

EEM336 Microprocessors I. Data Movement Instructions EEM336 Microprocessors I Data Movement Instructions Introduction This chapter concentrates on common data movement instructions. 2 Chapter Objectives Upon completion of this chapter, you will be able to:

More information

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top Microprocessors (0630371) Fall 2010/2011 Lecture Notes # 15 Stack Operations Objectives of the Lecture Runtime Stack PUSH Operation POP Operation Initializing the Stack PUSH and POP Instructions Stack

More information

IA32 Intel 32-bit Architecture

IA32 Intel 32-bit Architecture 1 2 IA32 Intel 32-bit Architecture Intel 32-bit Architecture (IA32) 32-bit machine CISC: 32-bit internal and external data bus 32-bit external address bus 8086 general registers extended to 32 bit width

More information

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000 Declaring Variables in Assembly Language As in Java, variables must be declared before they can be used Unlike Java, we do not specify a variable type in the declaration in assembly language Instead we

More information

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly II: Control Flow Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Processor State (x86-64) RAX 63 31 EAX 0 RBX EBX RCX RDX ECX EDX General-purpose

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST 2 Date : 02/04/2018 Max Marks: 40 Subject & Code : Microprocessor (15CS44) Section : IV A and B Name of faculty: Deepti.C Time : 8:30 am-10:00 am Note: Note: Answer any five complete

More information

Ethical Hacking. Assembly Language Tutorial

Ethical Hacking. Assembly Language Tutorial Ethical Hacking Assembly Language Tutorial Number Systems Memory in a computer consists of numbers Computer memory does not store these numbers in decimal (base 10) Because it greatly simplifies the hardware,

More information

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents. Intel Assembly Format of an assembly instruction: LABEL OPCODE OPERANDS COMMENT DATA1 db 00001000b ;Define DATA1 as decimal 8 START: mov eax, ebx ;Copy ebx to eax LABEL: Stores a symbolic name for the

More information

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,... COMPUTER ARCHITECTURE II: MICROPROCESSOR PROGRAMMING We can study computer architectures by starting with the basic building blocks Transistors and logic gates To build more complex circuits Adders, decoders,

More information

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015 CS165 Computer Security Understanding low-level program execution Oct 1 st, 2015 A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns

More information

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta 1 Reverse Engineering Low Level Software CS5375 Software Reverse Engineering Dr. Jaime C. Acosta Machine code 2 3 Machine code Assembly compile Machine Code disassemble 4 Machine code Assembly compile

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures! ISAs! Brief history of processors and architectures! C, assembly, machine code! Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 21: Generating Pentium Code 10 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Simple Code Generation Three-address code makes it

More information

We will first study the basic instructions for doing multiplications and divisions

We will first study the basic instructions for doing multiplications and divisions MULTIPLICATION, DIVISION AND NUMERICAL CONVERSIONS We will first study the basic instructions for doing multiplications and divisions We then use these instructions to 1. Convert a string of ASCII digits

More information

Assembler Programming. Lecture 2

Assembler Programming. Lecture 2 Assembler Programming Lecture 2 Lecture 2 8086 family architecture. From 8086 to Pentium4. Registers, flags, memory organization. Logical, physical, effective address. Addressing modes. Processor Processor

More information

Assembly II: Control Flow

Assembly II: Control Flow Assembly II: Control Flow Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)

More information

Instructions moving data

Instructions moving data do not affect flags. Instructions moving data mov register/mem, register/mem/number (move data) The difference between the value and the address of a variable mov al,sum; value 56h al mov ebx,offset Sum;

More information

EEM336 Microprocessors I. The Microprocessor and Its Architecture

EEM336 Microprocessors I. The Microprocessor and Its Architecture EEM336 Microprocessors I The Microprocessor and Its Architecture Introduction This chapter presents the microprocessor as a programmable device by first looking at its internal programming model and then

More information

Lecture (02) The Microprocessor and Its Architecture By: Dr. Ahmed ElShafee

Lecture (02) The Microprocessor and Its Architecture By: Dr. Ahmed ElShafee Lecture (02) The Microprocessor and Its Architecture By: Dr. Ahmed ElShafee ١ INTERNAL MICROPROCESSOR ARCHITECTURE Before a program is written or instruction investigated, internal configuration of the

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College February 9, 2016 Reading Quiz Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College September 25, 2018 Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between programmer

More information

CS 16: Assembly Language Programming for the IBM PC and Compatibles

CS 16: Assembly Language Programming for the IBM PC and Compatibles CS 16: Assembly Language Programming for the IBM PC and Compatibles Discuss the general concepts Look at IA-32 processor architecture and memory management Dive into 64-bit processors Explore the components

More information