11.1/36 Repeat: From Bits and Pieces Till Strings.

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

ICS312 Set 2 Representation of Numbers and Characters.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.c: Logical Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
Computer Organization & Assembly Language
80x86 Instruction Set Dr. Qiang Lin.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
8-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
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.
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
An Introduction to 8086 Microprocessor.
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Lecture 05: Assembly Language Programming (2). The 80x86 IBM PC and Compatible Computers Chapter 3 Arithmetic & Logic Instructions and Programs Chapter.
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF.
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
Number Systems Spring Semester 2013Programming and Data Structure1.
ICS312 Set 1 Representation of Numbers and Characters.
Types of Registers (8086 Microprocessor Based)
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
ICS312 Lecture13 String Instructions.
Processing String Data and Binary Data (continue)
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
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.
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
String Instructions String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data structures.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Khaled A. Al-Utaibi  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer.
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.
Chapter 8 String Operations. 8.1 Using String Instructions.
Chapter Nov-2010
Number Representation
Assembly 07 String Processing.
8086 Microprocessor.
Today we are going to discuss about,
Microprocessor Systems Design I
Microprocessor Systems Design I
EE3541 Introduction to Microprocessors
Machine control instruction
INSTRUCTION SET.
Assembly Language Programming Part 2
ECE 353 Introduction to Microprocessor Systems
Intel 8088 (8086) Microprocessor Structure
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Defining Types of data expression Dn [name] expression Dn [name]
Introduction to Assembly Language
Chapter 4 Data Movement Instructions
Intel 8088 (8086) Microprocessor Structure
Symbolic Instruction and Addressing
Shift & Rotate Instructions)
ADDITION Register Addition. ADD AX,BX AX=AX+BX 2. Immediate Addition.
Assembly Language for Intel-Based Computers, 5th Edition
Shift & Rotate Instructions)
Chapter 5 Arithmetic and Logic Instructions
Microprocessor and Assembly Language
Computer Organization and Assembly Language
Shift and Rotate Instructions.
Part I Data Representation and 8086 Microprocessors
Ch. 5 – Intel 8086 – study details from Yu & Marut
Presentation transcript:

11.1/36 Repeat: From Bits and Pieces Till Strings.

11.2/36 Overview Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.3/36 Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.4/36 Bit, Nibble, Byte, Word & Double Word Bit – The smallest information unit. Either 0 or 1, Nibble – four bits: from 0000 to 1111, Byte – eight bits from to , Word – sixteen bits: from to , Double Word – thirty two bits: from to

11.5/36 Bit, Nibble, Byte, Word & Double Word Nibble – 0110, Byte – , Word – , Double Word – MSB LSB

11.6/36 Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.7/36 Decimal, Binary & Hex … Regularly, we look upon numbers as they are represented in the decimal base: We got ten digits: 1, 2, 3, 4, 5, 6, 7, 8, 9 and 0, In the binary base we got two digits: 0 and 1, In the hexadecimal base we got sixteen digits: 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, and 0, We may convert numbers from each base to other.

11.8/36 Decimal, Binary & Hex (Cont’d) DecBinaryHex DecBinaryHex A B C D E F

11.9/36 Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.10/36 ASCII Code … ASCII is an acronym of American Standard Code for Information Interchange, This code assigns the letters of the alphabet, decimal digits from 0 to 9 and some additional symbols a binary number of 7 bits, putting the 8th bit in its off state or 0, This way each letter, digit or special character occupies one byte in the computer memory.

11.11/36 ASCII Code (Cont’d) 32H 46H 66H

11.12/36 Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.13/36 Unsigned, Signed numbers & 2’comp. Unsigned numbers: 0000 B = 0 10, 0011 B = 3 10, 1010 B = 10 10, 1110 B = 14 10, Only ‘Positive’ numbers, Signed numbers: Gives us the ability to mark numbers as positive or negative, What about sign and magnitude – the first bit will be dedicated to hold the number sign: 0 – Positive, 1 – Negative,

11.14/36 2’complement … But than – we got two zeros: 0000 B = The positive 0, 1000 B = The negative 0, So we got the 2’complement representation: 0011 B = 3 10, First, invert all bits: 1100 B = 3 10, (you may do so by the not command), Second, add 1, 1101 B = -3 10, We may achieve this representation in one step using the NEG (negate) command.

11.15/36 2’complement (Cont’d) With n bits you can represent numbers [-2 n-1, +2 n-1 -1] -1 is a string of 1s, -2 n-1 is 1 and the rest 0s, = 1000 B, = 1001 B, … = 1111 B, What numbers you deal with In the project? What is their range? What about ? OR (-30000) =

11.16/36 Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.17/36 The NOT Command Function: Invert bits: reg = NOT reg., Flags: Unchanged, ~ (~ X) = X xNot x 01 10

11.18/36 The OR Command Function: dst = dst OR src, Flags CF, OF, ZF, SF, PF, AF, x OR 0 = x, x OR 1 = 1, x OR x = x, x OR y = y OR x, (x OR y) OR z = x OR (y OR z), xyx OR y

11.19/36 The AND Command Function: dst=dst AND src, Flags CF, OF, ZF, SF, PF, AF, x AND 0 = 0, x AND 1 = x, x AND x = x, x AND y = y AND x, (x AND y) AND z = x AND (y AND z), xyx AND y

11.20/36 The TEST Command Function: Calculate dst AND src, Flags CF, OF, ZF, SF, PF, AF, Source is not destruct, xyx AND y

11.21/36 The XOR Command Function: dst = dst XOR src, Flags CF, OF, ZF, SF, PF, AF, x XOR 0 = x, x XOR 1 = ~x, x XOR x = 0, x XOR y = y XOR x, (x XOR y) XOR z = x XOR (y XOR z), xyx XOR y

11.22/36 Masking – Reset Assume we want to reset all bits in BX – excluding bit# 4 & #9, That is we want all other bits to become 0, But bits 4 & 9 to remain untouched. The proper mask is: (that is 0210H): FEDCBA Bit # The Mask BX AND BX The Mask

11.23/36 Masking – Set Assume we want to set bit# 6 in AX That is we want bit 6 to become 1, and all other bits to remain untouched. The proper mask is: (that is 0040H): FEDCBA Bit # The Mask AX OR AX 1 The Mask

11.24/36 Masking – Invert Assume we want to invert bits # 2 & 12 in DX That is: –If (bit# 2=1) reset it to 0, else set it to 1, –If (bit# 12=1) reset it to 0, else set it to 1, The proper mask is: (that is 1004H): FEDCBA Bit # The Mask DX XOR DX The Mask 1 0

11.25/36 Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.26/36 The Shift Commands … These are the shift commands: SHL, SHR, SAL, SAR, ROL, ROR, RCL and the RCR command, All work on 8 or 16 bits, All are executed once, or use CL as counter, All move bits one place to the left or one bit to the right, In all of them – the bit in the end (left or right) will go to the carry flag, The question is: from where are we getting the ‘new bit?’

11.27/36 The Shift Commands (Cont’d) … RegisterCF SHL: 0 RegisterCF SHR: 0 RegisterCF SAL: 0 RegisterCF SAR:

11.28/36 The Shift Commands (Cont’d) ROL: CF Register ROR: CF Register RCL: CF Register CF Register RCR:

11.29/36 Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.30/36 String Commands All String commands can handle byte or word data, These are the 5 pairs string commands: MOVSB & MOVSW, SCASB & SCASW, CMPSB & CMPSW, LODSB & LODSW, STOSB & STOSW, Usually they use: DS:SI as source and ES:DI as destination, All can be used with the prefix REP, REPE and REPNE.

11.31/36 The MOVSB & MOVSW Commands Move String do not affect the flags, MOVSB: copy byte: [SI] -> [DI], IF (df=0) than {si = si + 1, di = di + 1} else {si = si - 1, di = di - 1}, MOVSW: copy word: [SI] -> [DI], IF (df=0) than {si = si + 2, di = di + 2} else {si = si - 2, di = di - 2}

11.32/36 The Set / Clear DF Commands CLD: Clear Direction Flag, Format: CLD, Flags Affected: DF, Function: Resets DF to 0. Used with string commands, IF DF=0, indices (SI, DI) are incremented, STD: Set Direction Flag, Format: STD, Flags Affected: DF, Function: Sets DF to 1. Used with string commands. IF DF=1, indices (SI, DI) are decremented.

11.33/36 The CMPSB & CMPSB Commands Compare the current bytes (or words) of the source and destination strings by subtracting the destination from the source and recording the properties of the result in FLAGS, CMPSB: execute bytes comparison: [SI] - [DI], IF (df=0) than {si = si + 1, di = di + 1} else {si = si - 1, di = di - 1}, CMPSW: execute words comparison: [SI] - [DI], IF (df=0) than {si = si + 2, di = di + 2} else {si = si - 2, di = di - 2}

11.34/36 The SCASB & SCASW Commands Compare the current bytes (or words) of AL (or AX) and destination strings by subtracting the destination from the accumulator and recording the properties of the result in FLAGS, SCASB: execute bytes comparison: AL - [DI], IF (df=0) than {di = di + 1} else {di = di - 1}, SCASW: execute words comparison: AX - [DI], IF (df=0) than {di = di + 2} else {di = di - 2}

11.35/36 The STOSB and STOSW Commands Store String do not affect the flags, STOSB: copy byte: [AL] -> [DI], IF (df=0) than {di = di + 1} else {di = di - 1}, STOSW: copy word: [AX] -> [DI], IF (df=0) than {di = di + 2} else {di = di - 2}

11.36/36 The LODSB and LODSW Commands Load String do not affect the flags, LODSB: copy byte: [SI] -> [AL], IF (df=0) than {si = si + 1} else {si = si - 1}, LODSW: copy word: [SI] -> [AX], IF (df=0) than {si = si + 2} else {si = si - 2}

11.37/36 Code Example movah, [bp+4]; ah holds # of rows movdi, [bp+6]; output string address movsi, [bp+8]; input string address cld; clear direction flag for string commands moval, ‘ ‘; will be used in the stosb command xorch, ch; cx will be our columns counter Nxt_R:movcl, [bp+5]; cx holds # of columns Nxt_C:movsb; [di] <- [si], di++, si++ stosb ; [di] <- al, di++ loopNxt_C; end of row! movbyte ptr [di], 0dh; [di] <- CR, incdi movbyte ptr[di], 0ah; [di] <- LF, incdi decah; decrement # of rows jnzNxt_R; end of matrix? movbyte ptr[di], '$‘; Yes! – put the ‘end of string’ sign – ‘$’

11.38/36 Summary Bit, Nibble, Byte, Word & Double Word, Decimal, Binary & Hex, ASCII, Unsigned, Signed numbers & 2’complement, Logic Commands and masking, Shift Commands, String Commands.

11.39/36 Repeat: From Bits and Pieces Till Strings. The End.