Computer Architecture and System Programming Laboratory

Slides:



Advertisements
Similar presentations
ECE291 Computer Engineering II Lecture 24 Josh Potts University of Illinois at Urbana- Champaign.
Advertisements

I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
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
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
1 Programming in Machine Language SCSC 311 Spring 2011.
11.1/36 Repeat: From Bits and Pieces Till Strings.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
Bits and Bytes. BITWISE OPERATORS Recall boolean logical operators in Java… boolean logical operators: &, |, ^ not: ! Show truth tables.
LAB Flag Bits and Register
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.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
The x86 PC Assembly Language, Design, and Interfacing By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey © 2010, 2003, 2000, 1998 Pearson.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Logic (continuation) Boolean Logic and Bit Operations.
EET 250 Number systems. Introduction to Number Systems While we live in a world where the decimal number is predominant in our lives, computers and digital.
Arithmetic Flags and Instructions
Computer Architecture Lecture 12 by Engineer A. Lecturer Aymen Hasan AlAwady 17/3/2014 University of Kufa - Information Technology Research and Development.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.b: Arithmetic Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
Tamanna Chhabra, M. Oguzhan Kulekci, and Jorma Tarhio Aalto University.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly 03. Outline inc, dec movsx jmp, jnz Assembly Code Sections Labels String Variables equ $ Token 1.
5.6 String Processing Part 2. Sprintf(destnvar,…..regularprintf) Write formatted data to string Same as printf except the output is put in variable. A.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
Microprocessor MA Rahim Khan Computer Engineering and Networks Department.
Introduction to Computer Organization and Assembly Language
Sequencers SQO,SQC,SQL.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
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 5.
Computer Architecture and Assembly Language
Lec 3: Data Representation
Data Transfers, Addressing, and Arithmetic
Programming in Machine Language
A B C D E F G H U T S R Q P O N I J K L M Z Y X W V 6 Reset scores
The FLAGS Register An x bit means an unidentified value 9/12/2018
Morgan Kaufmann Publishers Computer Organization and Assembly Language
More on logical instruction and
Intel 8088 (8086) Microprocessor Structure
COMP3221: Microprocessors and Embedded Systems
MMX Multi Media eXtensions
Formatting Output.
Ken D. Nguyen Department of Computer Science Georgia State University
Chapter 7: Strings and Characters
Intel 8088 (8086) Microprocessor Structure
Processor Organization and Architecture
Shift & Rotate Instructions)
University of Gujrat Department of Computer Science
Shift & Rotate Instructions)
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Organization and Assembly Language
Computer Architecture and System Programming Laboratory
Ken D. Nguyen Department of Computer Science Georgia State University
Carnegie Mellon Ithaca College
Computer Architecture and System Programming Laboratory
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

Computer Architecture and System Programming Laboratory TA Session 12 x86-SSE text string processing instructions

X86-SSE Programming – Text Strings (SSE4.2)   An implicit-length text string uses a terminating End-Of-String (EOS) character. X86-SSE includes four SIMD text string instructions that are capable of processing text string fragments up to 128 bits in length. Suppose you are given a text string fragment and want to create a mask to indicate the positions of the uppercase characters within the string. For example, each 1 in the mask 1000110000010010b signifies an uppercase character in the corresponding position of the text string "Ab1cDE23f4gHi5J6". The desired character range and text string fragment are loaded into registers XMM1 and XMM2, respectively.

RFLAGS: 0x4831 = 0100100000110001b

RFLAGS: RFLAGS: RFLAGS: the output format bit 6 is set, which means that the mask value is expanded to bytes RFLAGS: multiple character ranges XMM1 contains two range pairs: one for uppercase letters and one for lowercase letters. RFLAGS: text string fragment that includes an embedded EOS (‘\0’) character ZF is set to 1 final mask value excludes matching range characters following EOS

CF flag – Reset if IntRes2 is equal to zero, set otherwise RFLAGS: multiple character ranges XMM1 contains two range pairs: one for uppercase letters and one for lowercase letters. RFLAGS is set in a non-standard manner in order to supply the most relevant information: CF flag – Reset if IntRes2 is equal to zero, set otherwise ZF flag – Set if any byte/word of xmm2/mem128 is null, reset otherwise SF flag – Set if any byte/word of xmm1 is null, reset otherwise OF flag – IntRes2[0] AF flag – Reset PF flag – Reset

AZ2az_mask: times 16 db ('a' - 'A’) result: times 16 db 0 db `\n\0` section .data str: db ‘Ab1cDE23f4gHi5J6’ AZ_mask: db ‘A', ‘Z’ times 14 db 0 imm: equ 01000100b AZ2az_mask: times 16 db ('a' - 'A’) result: times 16 db 0 db `\n\0` extern printf section .text global main main: enter movdqu xmm1, [AZ_mask] movdqu xmm2, [str] pcmpistrm xmm1, xmm2, imm movdqu xmm3, [AZ2az_mask] pand xmm0, xmm3 paddb xmm2, xmm0 movdqu [result], xmm2 mov rdi, result mov rax, 0 call printf leave ret MOVDQU xmm1, xmm2/m128 Move unaligned double quadword from xmm2/m128 to xmm1. PADDB xmm1, xmm2/m128 Add packed byte integers from xmm2/m128 and xmm1. PAND xmm1, xmm2/m128 Bitwise AND of xmm2/m128 and xmm1.

Equal any (imm[3:2] = 00). The result is a bit mask – 1 if the character belongs to a set, 0 if not. pcmpstrim xmm1, xmm2, 01000000b 00 ‘\0’ ‘1’ ‘k’ ‘b’ ‘a’ ‘2’ xmm1 00 ‘\0’ ‘1’ ‘k’ ‘C’ ‘a’ xmm2 00 FF xmm0 Equal each (imm[3:2] = 10). The result is a bit mask – 1 if the corresponding bytes are equal, 0 if not equal. pcmpstrim xmm1, xmm2, 01001000b 00 ‘\0’ ‘1’ ‘k’ ‘b’ ‘a’ xmm1 00 ‘\0’ ‘1’ ‘k’ ‘C’ ‘a’ xmm2 00 FF xmm0

Equal ordered (imm[3:2] = 11). The result is a bit mask – 1 if the substring is found at the corresponding position, 0 otherwise. pcmpstrim xmm1, xmm2, 01001100b 00 ‘e’ ‘W’ xmm1 ‘!’ ‘d’ ‘e’ ‘W’ ‘B’ ‘l’ ‘i’ ‘n’ ‘h’ xmm2 00 FF xmm0

RCX = 16 (invalid index) rcx RFLAGS: RCX IntRes1 calculation – mask according to the given range bit index in IntRes1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 bit value in IntRes1 Negative- IntRes2 calculation bit index in IntRes1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 bit value in IntRes1 RCX = index of least significant set bit in IntRes2 RCX = 16 (invalid index) RCX

RCX = 11 (index of ‘\0’ character, or length of string) RFLAGS: rcx IntRes1 calculation – mask according to the given range bit index in IntRes1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 bit value in IntRes1 Negative- IntRes2 calculation bit index in IntRes1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 bit value in IntRes1 RCX = index of least significant set bit in IntRes2 RCX = 11 (index of ‘\0’ character, or length of string) RCX

rcx RFLAGS: RCX

first loop cycle: second loop cycle: section .data RFLAGS: rcx section .data str: db ‘Ab1cDE23f4gHi5J6’ db ‘Ab1cDE23f4g\0’ EOS_mask: db 0x1,0xFF times 14 db 0 imm: equ 00010100b section .text global strlen strlen: enter xor rax xor rcx movdqu xmm1, [EOS_mask] .loop add rax, rcx pcmpistri xmm1, [str+rax], imm jnz .loop leave ret second loop cycle: RFLAGS: rcx

RCX