Computer Architecture and System Programming Laboratory

Slides:



Advertisements
Similar presentations
Assembly Language – 1.
Advertisements

Practical Malware Analysis
COMP 2003: Assembly Language and Digital Logic
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
8051 ASSEMBLY LANGUAGE PROGRAMMING
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Code Generation Gülfem Savrun Yeniçeri CS 142 (b) 02/26/2013.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Assembly Language A Brief Introduction. Unit Learning Goals CPU architecture. Basic Assembler Commands High level Programming  Assembler  Machine Language.
Computer Architecture and Assembly Language. Byte structure : a byte has 8 bits MSB (Most Significant Bit) LSB (Least Significant Bit) Data Representation.
Module 3 Instruction Set Architecture (ISA): ISA Level Elements of Instructions Instructions Types Number of Addresses Registers Types of Operands.
1 ICS 51 Introductory Computer Organization Fall 2009.
CNIT 127: Exploit Development Ch 1: Before you begin.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)
Computer Architecture and Assembly Language
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Chapter Overview General Concepts IA-32 Processor Architecture
Computer Architecture and Assembly Language
Practical Session 3.
Exploiting & Defense Day 1 Recap
Stack Operations Dr. Hadi AL Saadi.
Assembly function call convention
Instruction Set Architecture
Computer Architecture and Assembly Language
Programmable System on Chip
Homework Reading Lab with your assigned section starts next week
Assembly language.
Credits and Disclaimers
Assembly Lab 3.
Computer Architecture and Assembly Language
Assembly Language programming
x86 Processor Architecture
Computer Architecture and Assembly Language
Aaron Miller David Cohen Spring 2011
Homework In-line Assembly Code Machine Language
Introduction to Compilers Tim Teitelbaum
Basic Microprocessor Architecture
Assembly IA-32.
Homework Reading Continue work on mp1
Assembly Language Programming V: In-line Assembly Code
COAL Chapter 1,2,3.
Introduction to Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
CS-401 Computer Architecture & Assembly Language Programming
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
CS 301 Fall 2002 Computer Organization
MIPS Procedure Calls CSE 378 – Section 3.
Practical Session 4.
Multi-modules programming
Week 2: Buffer Overflow Part 1.
Computer Architecture CST 250
X86 Assembly Review.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Computer Architecture and System Programming Laboratory
Machine-Level Programming II: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Other Processors Having learnt MIPS, we can learn other major processors. Not going to be able to cover everything; will pick on the interesting aspects.
CSC 497/583 Advanced Topics in Computer Security
Computer Organization and Assembly Language
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

Computer Architecture and System Programming Laboratory TA Session 1 Memory basics Register file Assembly language basics MOV + RESB code example

Data Representation Basics bit – basic binary information unit: 0/1 byte – sequence of 8 bits: 7 6 5 4 3 2 1 MSB (Most Significant Bit) LSB (Least Significant Bit) Main Memory (RAM) is array of bytes, addressed by 0 to 232-1. 232 bytes = 4∙210∙3 bytes = 4 G bytes RAM 232-1 2K-1 1 … word – sequence of 2 bytes byte address space dword – sequence of 4 bytes physical memory byte

Registers Register file - CPU unit which contains 32-bit registers. general purpose registers EAX, EBX, ECX, EDX (Accumulator, Base, Counter, Data) index registers ESP, EBP, ESI, EDI (Stack pointer - contains address of last used dword in the stack, Base pointer – contains address of current activation frame, Source index, Destination Index) flag register / status register EFLAGS Instruction Pointer / Program Counter EIP - contains address of next instruction that is going to be executed (at run time) - automatically is changed by jump, procedure call, and return instructions High byte Low byte Extended 16-bit register Full list of registers can be found here.

Instruction pointer EIP contains address of next instruction that is going to be executed (at run time) automatically is changed by jump, procedure call, and return instructions RAM 2051 2050 2048 … instr. 3 instr. 2 instr.1 executable file header: (some info) …. code: instruction 1 instruction 2 instruction 3 load process image into RAM cs (code segment) CPU EIP = CPU takes next instruction to execute Full list of registers can be found here.

Instruction pointer EIP contains address of next instruction that is going to be executed (at run time) automatically is changed by jump, procedure call, and return instructions RAM 2051 2050 2048 … instr. 3 instr. 2 instr.1 executable file header: (some info) …. code: instruction 1 instruction 2 instruction 3 load process image into RAM cs (code segment) CPU EIP = CPU takes next instruction to execute Full list of registers can be found here.

Assembly Language Program consists of processor instructions, assembler directives, and data translated by assembler into machine language instructions (binary code) that can be loaded into memory and executed NASM - Netwide Assembler - is assembler for x86 architecture Example: assembly code: mov al, 0x61 ; load al with 97 decimal (61 hex) AL register binary code: 10110000 01100001 1 1011 a binary code (opcode) of instruction 'MOV' 0 specifies if data is byte (‘0’) or full size 16/32 bits (‘1’) 000 a binary identifier for a register 'AL' 01100001 a binary representation of 97 decimal (97d = (int)(97/16)*10 + (97%16 converted to hex digit) = 61h)

label: opcode operands ; comment Basic structure of an assembly-language instruction label: opcode operands ; comment optional fields - each instruction has its address in RAM - we mark an instruction with a label to refer this instruction in code - label equivalents to memory address that it represents - (non-local) labels have to be unique JMP tells the processor that the next instruction to be executed is located at the label that is given as part of jmp instruction. Example: movLabel: mov al, 0x61 … jmp movLabel Notes: - backslash (\) : if a line ends with backslash, the next line is considered to be a part of the backslash-ended line - no restrictions on white space within a line

Example of assembler directive buffer: resb 4 ; reserves 4 bytes RAM  mov buffer, 2 = mov 2048, 2  mov [buffer], 2 = mov [2048], 2 4 bytes Appropriate C code: int buffer; buffer = 2; buffer 2048  mov dword [buffer], 2 = mov dword [2048], 2 char buffer[4]; buffer[0] = 2; mov byte [buffer], 2 or mov word [buffer], 2 or short int buffer[2]; buffer[0] = 2; or …

Instruction Arguments A typical instruction has two operands: - target operand (left) - source operand (right) 3 kinds of operands: - immediate - register - memory location mov [buffer], ax mov ax, 2 target operand source operand target operand source operand register immediate memory location register Note that x86 processor does not allow both operands be memory locations. mov [var1],[var2]