Practical Session 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.

Slides:



Advertisements
Similar presentations
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Advertisements

ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
80x86 Instruction Set Dr. Qiang Lin.
Introduction to Assembly Here we have a brief introduction to IBM PC Assembly Language –CISC instruction set –Special purpose register set –8 and 16 bit.
Assembly 02. Outline mov Command Registers Memory EFLAGS Arithmetic 1.
Practical Session 3 Computer Architecture and Assembly Language.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Shift and Rotate Instructions
Practical Session 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h  Int 21 –A hexadecimal.
CoE3DJ4 Digital Systems Design
11.1/36 Repeat: From Bits and Pieces Till Strings.
Faculty of Engineering, Electrical Department,
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Arithmetic Flags and Instructions
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
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.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
What is a program? A sequence of steps
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.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly 06. Outline cmp (review) Jump commands test mnemonic bt mnemonic Addressing 1.
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
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.
Bitwise and Logical Manipulations Assembly Language Programming University of Akron Dr. Tim Margush.
Practical Session 2 Computer Architecture and Assembly Language.
Practical Session 3 Computer Architecture and Assembly Language.
Assembly language programming
Computer Architecture and Assembly Language
Format of Assembly language
Data Transfers, Addressing, and Arithmetic
Practical Session 2.
Microprocessor Systems Design I
Chapter 3 Bit Operations
Machine control instruction
Assembly Language Programming Part 2
UNIT: 2 INSTRUCTION SET OF 8086.
Defining Types of data expression Dn [name] expression Dn [name]
Introduction to Assembly Language
Practical Session 2.
Shift & Rotate Instructions)
Shift & Rotate Instructions)
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Shift, Multiply, and Divide
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Microprocessor and Assembly Language
Computer Organization and Assembly Language
Shift and Rotate Instructions.
Computer Architecture and Assembly Language
CS-401 Computer Architecture & Assembly Language Programming
Presentation transcript:

Practical Session 2

Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and. (. has a special meaning) label can be prefixed with a $ to indicate that it is intended to be read as an identifier and not a reserved word Example: if some other module you are linking with defines a symbol called eax, you can refer to $eax in NASM code to distinguish the symbol from the register.

Flags Flags as a whole is a single 16-bit register buried inside the CPU. Of those 16 bits, 9 are actually used as flags on the x86. A flag is a single bit of information whose meaning is independent from any other bit. Each of the Flags register's nine flags has a two-letter symbol by which most programmers know them. OF— The Overflow flag is set when the result of an operation becomes too large to fit in the operand it originally occupied. SF— The Sign flag becomes set when the result of an operation forces the operand to become negative. ZF— The Zero flag becomes set when the results of an operation become zero. CF— The Carry flag is by far the most useful flag in the Flags register, and the one you will have to pay attention to most. If the result of an arithmetic or shift operation "carries out" a bit from the operand, CF becomes set.

Sections Hold the bulk of object file information for the linking view: instructions, data, symbol table, relocation information, and so on. Important types:.bss - This section holds uninitialized data that contribute to the program’s memory image. The section occupies no file space..data and.data1 - These sections hold initialized data that contribute to the program’s memory image. rodata and.rodata1 - These sections hold read-only data that typically contribute to a non-writable segment in the process image..text - This section holds the ‘‘text,’’ or executable instructions, of a program.

Pseudo-instructions Pseudo-instructions are things which, though not real x86 machine instructions, are used in the instruction field anyway because that's the most convenient place to put them. The notion of type in assembly language is almost wholly a question of size. You can define named variables in your assembly language programs using such pseudo-instructions as DB and DW. Initialized data: something that comes with a value, and not just a box that will accept a value at some future time. A variable is defined by associating an identifier with a data definition pseudo-instruction, such as DB, DW, DD, etc.

RESB, RESW, RESD, RESQ AND REST: declaring uninitialized storage space Example: 1. buffer: resb 64 ; reserve 64 bytes 2. word_var: resw 1 ; reserve a word 3. real_array resq 10 ; array of ten real numbers Note: you can not make any assumption about values of a storage space cells.

EQU : defining constants EQU defines a symbol to a given constant value: when EQU is used, the source line must contain a label. The action of EQU is to define the given label name to be the value of its (only) operand. This definition cannot changed later. Example: FOO: EQU 1 ; FOO = 1

TIMES : Repeating Instructions or Data The TIMES prefix causes the instruction to be assembled multiple times ( partly NASM's equivalent of the DUP). The argument to TIMES is not just a numeric constant, but a numeric expression. TIMES can be applied to ordinary instructions, so you can code trivial unrolled loops. Example: zerobuf: times 64 db

Effective Addresses An effective address is any operand to an instruction which references memory. Effective addresses, in NASM, have a very simple syntax: they consist of an expression evaluating to the desired address, enclosed in square brackets. Examples: wordvar: dw 123 mov ax,[wordvar] ; ax = 0x007b (In Little Endian Format = 0x7b00) mov ax,[wordvar+1] ; ax = 0x0000

Constants NASM understands four different types of constant: numeric, character, string and floating points. 1. numeric constants - A numeric constant is simply a number. NASM allows to specify numbers in a variety of number bases, in a variety of ways: suffix H, Q and B for hex, octal and binary, etc. Examples: mov ax,100 ; decimal mov ax,0a2h ; hex mov ax,777q ; octal mov ax, b ; binary

2. Character Constants A character constant consists of up to 4 characters enclosed in either single or double quotes. A character constant with more than one character will be arranged with little- endian order in mind. Examples: mov eax,'abcd' The constant generated is not 0x , but 0x , so that if you were then to store the value into memory, it would read abcd rather than dcba. That way, it is stored “backwards” in eax.

3. String Constants String constants are only acceptable to some pseudo-instructions, namely the DB family and INCBIN. A string constant looks like a character constant, only longer. It is treated as a concatenation of maximum-size character constants for the conditions. Examples: db 'hello' ; string constant db 'h','e','l','l','o' ; equivalent character constants

Advanced Instructions MUL - Unsigned Integer Multiply IMUL - Signed Integer Multiply MUL/IMUL r/m MUL performs unsigned integer multiplication, and IMUL perform signed integer multiplication.. The other operand to the multiplication, and the destination operand are implicit, in the following way: For MUL r/m8, AL is multiplied by the given operand. the product is stored in AX. For MUL r/m16, AX is multiplied by the given operand. The product is stored in DX:AX. For MUL r/m32, EAX is multiplied by the given operand. The product is stored in EDX:EAX.

Examples: mov bl,5 ; multiplier mov al,9; multipicand mul bl ; ax = 45 mov bx, 8000h mov ax, 2000h mul bx ; result = hex mov al, 0x80 ; mov bl, 0x40 ; imul bl ; result = hex E000

Loop definition: LOOP, LOOPE, LOOPZ, LOOPNE, LOOPNZ: loop with counter * for all the possible variants of operands look at NASM manual, B Example: mov ax, 1 mov cx, 3 my_ loop: add ax, ax loop my_ loop, cx 1. decrements its counter register (in this case it is CX register) 2. if the counter does not become zero as a result of this operation, it jumps to the given label Note: counter register can be either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used. LOOPE (or its synonym LOOPZ ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ ) jumps only if the counter is nonzero and the zero flag is clear.

SHL, SHR : Bitwise Logical Shifts SHL r/m8/m16/m32 1/CL/imm8 SHR r/m8/m16/m32 1/CL/imm8 SHL and SHR perform a logical shift operation on the given source/destination (first) operand. The vacated bits are filled with zero. The number of bits to shift by is given by the second operand. The shifted bit enters the Carry Flag. Example: mov CL, 3 mov AL, b ; AL = shr AL, 1 ; shift right 1 AL = shr AL, CL; shift right 3 AL = Perform division/multiplication with 2.

SAL, SAR : Bitwise Arithmetic Shifts SAL r/m8/m16/m32 1/CL/imm8 SAR r/m8/m16/m32 1/CL/imm8 SAL and SAR perform an arithmetic shift operation on the given source/destination (first) operand. The vacated bits are filled with zero for SAL, and with copies of the original high bit of the source operand for SAR. Example: mov CL, 3 mov AL, b ; AL = sar AL, 1 ; shift right 1 AL = sar AL, CL; shift right 3 AL =

ROL, ROR : Bitwise Rotate ROL r/m8/m16/m32 1/CL/imm8 ROR r/m8/m16/m32 1/CL/imm8 ROL and ROR perform a bitwise rotation operation on the given source/destination (first) operand. Thus, for example, in the operation ROL AL,1, an 8-bit rotation is performed in which AL is shifted left by 1 and the original top bit of AL moves round into the low bit. Example: mov CL, 3 mov BH, b ; BH = rol BH, 01 ; rotate left 1 bit BH = rol BH, CL; rotate left 3 bits BH =

RCL, RCR : Bitwise Rotate through Carry Bit RCL r/m8/m16/m32 1/CL/imm8 RCR r/m8/m16/m32 1/CL/imm8 RCL and RCR perform a 9-bit, 17-bit or 33-bit bitwise rotation operation, involving the given source/destination (first) operand and the carry bit. Thus, for example, in the operation RCL AL,1, a 9-bit rotation is performed in which AL is shifted left by 1, the top bit of AL moves into the carry flag, and the original value of the carry flag is placed in the low bit of AL. Example: mov BH, b ; BH = ;CF = 0 rcl BH, 01 ; rotate left 1 bit BH = ;CF = 1