Computer Architecture and System Programming Laboratory

Slides:



Advertisements
Similar presentations
Assembly Language Fundamentals
Advertisements

Department of Computer Science and Software Engineering
Computer Organization & Assembly Language
Assembly 02. Outline mov Command Registers Memory EFLAGS Arithmetic 1.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Practical Session 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.
Practical Session 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.
Ch. 5 from Yu & Marut. Registers 14(16-bit) registers: 1.Data reg. – to hold data for an op. 2.Address reg – to hold addr of an instruction or data.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Electrical Engineering Department Engineering College Prince Sattam bin Abdul Aziz University Text Book: - Triebel and Singh, "The 8088 and 8086 Microprocessors",
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
LAB Flag Bits and Register
Faculty of Engineering, Electrical Department,
Computer Architecture and Assembly Language Practical session outline Introduction 80x86 assembly –Data storage –The registers –Flags –Instructions Assignment.
Lecture 4 ( Assembly Language).
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Computer Architecture and Assembly Language. Byte structure : a byte has 8 bits MSB (Most Significant Bit) LSB (Least Significant Bit) Data Representation.
Arithmetic Flags and Instructions
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Assembly 03. Outline inc, dec movsx jmp, jnz Assembly Code Sections Labels String Variables equ $ Token 1.
Review of Assembly language. Recalling main concepts.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
Practical Session 2. Flags Register (Status Register) A flag is a single bit of information whose meaning is independent from any other bit Each flag.
Introduction to Computer Organization and Assembly Language
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Computer Architecture and Assembly Language
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Practical Session 2 Computer Architecture and Assembly Language.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
Introduction to assembly programmıng language
Data Transfers, Addressing, and Arithmetic
Computer Architecture and Assembly Language
Microprocessor Systems Design I
Practical Session 2.
ICS312 SET 7 Flags.
The FLAGS Register An x bit means an unidentified value 9/12/2018
Microprocessor and Assembly Language
Assembly IA-32.
Computer Organization & Assembly Language
Defining Types of data expression Dn [name] expression Dn [name]
X86’s instruction sets.
Introduction to Assembly Language
Chapter 4: Instructions
Lecture 4 ( Assembly Language).
Flags Register & Jump Instruction
Practical Session 2.
תכנות בסיסי בשפת סף פרק 5 מצגת 3.
Shift & Rotate Instructions)
University of Gujrat Department of Computer Science
Shift & Rotate Instructions)
Computer Architecture and System Programming Laboratory
Chapter 5 Arithmetic and Logic Instructions
Assembler Directives end label end of program, label is entry point
Chapter 8: Instruction Set 8086 CPU Architecture
Computer Architecture and System Programming Laboratory
Computer Architecture and Assembly Language
Introduction to 8086 Assembly Language
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Ch. 5 – Intel 8086 – study details from Yu & Marut
Part IV The FLAGS Register
Presentation transcript:

Computer Architecture and System Programming Laboratory TA Session 2

d<size> – declare initialized data d<size> initial value <size> value <size> filed Pseudo-instruction 1 byte byte DB 2 bytes word DW 4 bytes double word DD 8 bytes quadword DQ 10 bytes tenbyte DT 16 bytes double quadword DDQ Examples: var: db 0x55 ; define a variable var of size byte, initialized by 0x55 var: db 0x55,0x56,0x57 ; three bytes in succession var: db 'a‘ ; character constant 0x61 (ascii code of ‘a’) var: db 'hello’,10 ; string constant var: dw 0x1234 ; 0x34 0x12 var: dw ‘A' ; 0x41 0x00 – complete to word var: dw ‘ABC' ; 0x41 0x42 0x43 0x00 – complete to word var: dd 0x12345678 ; 0x78 0x56 0x34 0x12

RFLAGS - Flag Register (Status Register) flag is a single independent bit of status information each flag has a two-letter symbol name … … Status Flags

CF - Carry Flag CF gets ‘1’ if result is larger than "capacity" of target operand 11111111b + 00000001b = 100000000b = 0  CF = 1 CF gets ‘1’ if subtract larger number from smaller (borrow out of “capacity” of target operand) 00000000b - 00000001b = 11111111b  CF = 1 00000000b-00000001b ≡ 100000000b-00000001b ≡ 11111111b otherwise CF gets ‘0’ In unsigned arithmetic, watch the carry flag to detect errors. In signed arithmetic ignore CF flag. 00000000b - 00000001b = 11111111 unsigned arithmetic  11111111b = 255 (decimal)  got the wrong answer signed arithmetic  11111111b = -1 (decimal)  ignore CF flag

OF – Overflow Flag 01100000b + 10010000b = 11110000b  OF = 0 sign-bit-off operands + sign-bit-on result  OF gets ‘1’ 01000000b + 01000000b = 10000000b OF = 1 sign-bit-on operands + sign-bit-off result  OF gets ‘1’ 10000000b + 10000000b = 100000000b = 0  OF = 1 otherwise OF gets ‘0’ 01000000b + 00010000b = 01010000b  OF = 0 01100000b + 10010000b = 11110000b  OF = 0 10000000b + 00010000b = 10010000b  OF = 0 11000000b + 11000000b = 10000000b  OF = 0 In signed arithmetic, watch the overflow flag to detect errors – addition of two positive numbers results negative, or addition two negative numbers results positive. In unsigned arithmetic ignore OF flag.

ZF, SF, PF, and AF Flags ZF – Zero Flag - set if a result is zero; cleared otherwise add 0, 0  ZF = 1 SF – Sign Flag – set if a result is negative (i.e. MSB of the result is 1) 00000000b - 00000001b = 11111111b  SF = 1 PF – Parity Flag - set if low-order eight bits of result contain an even number of "1" bits; cleared otherwise 1111111111010000b + 0000000000001000b = 1111111111011000b  4 bits are ‘1’  PF = 1) 1111000011000000b + 0000000000001000b = 1111000011001000b  3 bits are ‘1’  PF = 0) AF – Auxiliary Carry Flag (or Adjust Flag) is set if there is a carry from low nibble (4 bits) to high nibble or a borrow from a high nibble to low nibble 00001111b + 00000001b = 00010000b  AF = 1 00010000b - 0000001b = = 00001111b  AF = 1 nibble nibble nibble nibble

Instructions seen till now – affecting flags MOV NOT JMP* does not affect flags NEG The CF flag set to 0 if the source operand is 0; otherwise it is set to 1. The OF, SF, ZF, AF, and PF flags are set according to the result. AND OR The OF and CF flags are cleared; the SF, ZF, and PF flags are set according to the result. The state of the AF flag is undefined DEC INC The CF flag is not affected. The OF, SF, ZF, AF, and PF flags are set according to the result ADD ADC SUB SBB The OF, SF, ZF, AF, PF, and CF flags are set according to the result. CMP Modify status flags in the same manner as the SUB instruction The full set of instructions can be found here.

Little Endian - store the least significant byte in the lowest address [var+3] [var+2] [var+1] [var] 0x12 0x34 0x56 0x78 var: dd 0x12345678 mov eax, 0x12345678 EAX 0x78 0x56 0x34 0x12 string is translated by NASM into numeric value in reversed order: ‘abcd’  0x64636261 Thus, when inserted into memory, we get it in source order var: dd ‘abcd’ [var+3] [var+2] [var+1] [var] 0x64 0x63 0x62 0x61 mov eax, ‘abcd’ EAX 0x61 0x62 0x63 0x64 register into memory  reversed order mov [buffer], eax ; 0x61 0x62 0x63 0x64 memory into register  reversed order mov eax, [buffer] ; 0x64 0x63 0x62 0x61

Sections Every process consists of sections that are accessible to the process during its execution. Data .bss - holds uninitialized data; occupies (almost) no space .data and .data1 - holds initialized data .rodata and .rodata1 - holds read-only data Text .text – holds executable instructions of a program Stack* – contains information + local variables that is saved for each function call Heap – contains dynamically allocated memory * Stack pointer is normally initialized to point to the top of the heap and proceed downward. In fact, we can point to any location we like and manage any area of memory as the stack. program (.exe file) creates its own memory space in the RAM  process loaded from .exe file

Sections Every process consists of sections that are accessible to the process during its execution. Data .bss - holds uninitialized data; occupies (almost) no space .data and .data1 - holds initialized data .rodata and .rodata1 - holds read-only data Text .text – holds executable instructions of a program Stack* – contains information + local variables that is saved for each function call Heap – contains dynamically allocated memory * Stack pointer is normally initialized to point to the top of the heap and proceed downward. In fact, we can point to any location we like and manage any area of memory as the stack. section .bss BUFFLEN equ 1024 buff: resb BUFFLEN section .rodata LC0: db 'Hello world!' section .data an: dd 0 section .text mov ax, 2 ... Example : char a[10]; int b = 1; const int i = 10; main() { int aL=1, cL; char * ptr = (char *) malloc(4); cL= b+aL+i; } ----> .bss ----> .data ----> .rodata ----> local variables on Stack ----> Heap + Stack ----> .text