Processing String Data and Binary Data (continue)

Slides:



Advertisements
Similar presentations
Defining and processing tables
Advertisements

Instruction Set of 8086 Engr. M.Zakir Shaikh
Registers of the 8086/ /2002 JNM.
Department of Computer Science and Software Engineering
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
Assembly Language :CSC 225 (Lec#4: Flag Register and Conditional Statements) By Dr. Syed Noman.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Direct video practice and Keyboard Operations
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.
Factorial of a number data segment x1 db 4 fact dw ? data ends
Fundamentals of Assembly language
Microprocessor Programming II
3.7 String Instructions Specifying the Operands’ Size and Address and the String Direction STRING = a data collection in memory. String ELEMENTS can be:
COSC 456 Lesson 8 Cool Codes ADD AL,SIAL AL + SI ADD AL,[SI]AL AL + [SI] INC BXBX BX + 1 INC [BX]Ambiguity error INC BYTE PTR [BX][BX] [BX] + 1 INC WORD.
11.1/36 Repeat: From Bits and Pieces Till Strings.
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
String-Introduction String is a series of bytes or a series of words in sequential memory locations. Index registers - SI (Data segment) - DI (Extra segment)
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#5) By Dr. Syed Noman.
Strings, Procedures and Macros
Arithmetic Flags and Instructions
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
ICS312 Lecture13 String Instructions.
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
Introduction to Assembly Language Programming 1. Overview of Assembly Language  Advantages:  Disadvantages: Faster as compared to programs written using.
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.
String Processing Chapter 10 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Microprocessor Programming II To discuss more complicated programming techniques Flag control instructions Compare and jump Subroutines Loop and string.
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.
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.
Microprocessor MA Rahim Khan Computer Engineering and Networks Department.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
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.
Introduction to assembly programmıng language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Microprocessor Systems Design I
Assembly 07 String Processing.
8086 Microprocessor.
Today we are going to discuss about,
EE3541 Introduction to Microprocessors
EE3541 Introduction to Microprocessors
INSTRUCTION SET.
INSTRUCTION SET.
Assembly Language Programming Part 2
Intel 8088 (8086) Microprocessor Structure
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
اصول اساسی برنامه نویسی به زبان اسمبلی
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Chapter 4: Instructions
ارايه دهنده : حسن عسكرزاده
Chapter 4 Data Movement Instructions
اصول اساسی برنامه نویسی به زبان اسمبلی
תכנות בסיסי בשפת סף פרק 5 מצגת 3.
Assembly Language for Intel-Based Computers, 5th Edition
T opic: S TRING I NSTRUCTION P RESENTED B Y: N OOR FATIMA M AHA AKRAM ASIF.
Chapter 5 Arithmetic and Logic Instructions
Computer Architecture and System Programming Laboratory
UNIT-II Assembly Language Programs Involving Logical
CNET 315 Microprocessor & Assembly Language
Chapter 8: Instruction Set 8086 CPU Architecture
UNIT-II ADDRESSING MODES & Instruction set
Presentation transcript:

Processing String Data and Binary Data (continue)

Code for last practice exercise DATASEG SEGMENT PARA 'Data' ; Please insert your data declaration here DES_STR DB 50 DUP ('$') ParaList label byte maxlen DB 50 actlen DB ? SRC_STR DB 50 DUP ('$') DATASEG ENDS

Code for last practice exercise ; Code for reading input from keyboard MOV AH, 0AH LEA DX, ParaList INT 21H ; Code for reversing the string LEA SI, SRC_STR LEA DI, DES_STR MOV CH,0 MOV CL, ACTLEN DEC CX ADD DI, CX INC CX L10: LODSB MOV [DI], AL DEC DI LOOP L10

CMPSB, CMPSW Compare String Instruction Compare bytes: ES:[DI] from DS:[SI]. DS:[SI] - ES:[DI] set flags according to result: OF, SF, ZF, AF, PF, CF if DF = 0 then SI = SI + 1 DI = DI + 1 else SI = SI - 1 DI = DI - 1

Example STRING1 DB ‘COMPUTER’ STRING2 DB ‘COMPUTER’ MOV CX, 8 LEA DI, STRING2 LEA SI, STRING1 REPE CMPSB JNE exit exit: …

REPE (repeat if equal) Repeat following CMPSB, CMPSW, SCASB, SCASW instructions while ZF = 1 (result is Equal), maximum CX times. check_cx: if CX <> 0 then do following chain instruction CX = CX - 1 if ZF = 1 then: go back to check_cx else exit from REPE cycle

SCASB: SCAN STRING INSTRUCTION Scan a string for a specified value. Continue to Compare bytes: AL from ES:[DI] while the comparison is not equal or until CX is 0 (Similar to indexOf in java or strstr in C) ES:[DI] - AL set flags according to result: OF, SF, ZF, AF, PF, CF if DF = 0 then DI = DI + 1 else DI = DI - 1

Example: STRING1 DB ‘COMPUTER’ … MOV AL, ‘r’ MOV CX, 8 LEA DI, STRING1 REPNE SCASB

REPNE Repeat following CMPSB, CMPSW, SCASB, SCASW instructions while ZF = 0 (result is Not Equal), maximum CX times. check_cx: if CX <> 0 then do following chain instruction CX = CX - 1 if ZF = 0 then: go back to check_cx else exit from REPNE cycle

Replicating a pattern PATTERN DB ‘|----|’ RESULT DB 42 DUP (‘ ‘) MOV CX, 21 LEA DI, RESULT LEA SI, PATTERN REP MOVSW

Lab/Practice 1. Open your browser and open this page: C:\emu8086\documentation\8086_instruction_set.html And C:\emu8086\documentation\8086_and_dos_interrupts.html 2. Open your emu8086 software 3. Cut and paste (or type) the following code (as shown in the next page) and save move.asm

page 60,132 TITLE MovePractice Move ; --------------------------------------------- STACK SEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACK ENDS ; ---------------------------------------------- DATASEG SEGMENT PARA 'Data' ; Please insert your data declaration here DATASEG ENDS CODESEG SEGMENT PARA 'Code' MAIN PROC FAR MOV AX, DATASEG MOV DS, AX MOV ES, AX ; Please insert your code here MOV AX,4C00H ;exit procedure INT 21H MAIN ENDP CODESEG ENDS END MAIN ;End of program

Practice 4. Modify your code so that: - Define: BUS_TITLE DB ‘COMPUTER WIZARDS’ - WORK_SPACE DB 16 DUP(20H) - Move BUS_TITLE to WORK_SPACE from left to right (CLD) - MOV BUS_TITLE to WORK_SPACE from right to left (STD) - COMPARE BUS_TITLE with WORK_SPACE, print “equal” if equal, print “not equal” if not 5. Compile and run

Code ; Data segment declaration EQUALPROMPT DB 'Equal', '$' NOTEQUALPROMPT DB 'Not Equal', '$' BUS_TITLE DB 'COMPUTER WIZARDS','$' WORK_SPACE DB 17 DUP(20H)

Code LEA SI, BUS_TITLE LEA DI, WORK_SPACE MOV CX, 17 REP MOVSB ; Moving from left to right CLD LEA SI, BUS_TITLE LEA DI, WORK_SPACE MOV CX, 17 REP MOVSB ; Moving from right to left STD LEA SI, BUS_TITLE+16 LEA DI, WORK_SPACE+16

Code ; Print equal if equal, print not equal if not MOV CX, 17 LEA DI, BUS_TITLE LEA SI, WORK_SPACE REPE CMPSB JE EQUALPRINT MOV AH, 09H LEA DX, NOTEQUALPROMPT INT 21H JMP exit EQUALPRINT: LEA DX, EQUALPROMPT

Binary Data ADC CBW NEG SBB

ADC Add with Carry. Algorithm: operand1 = operand1 + operand2 + CF

Example STC ; set CF =1 MOV AL, 5 ; AL = 5 ADC AL, 1 ; AL =?

CBW Convert byte into word. Algorithm: if high bit of AL = 1 then: AH = 255 (0FFh) else AH = 0

Example MOV AX, 0 ; AH = 0, AL = 0 MOV AL, -5 ; AX = 000FBh (251) CBW ; AX = 0FFFBh (-5)

NEG Negate. Makes operand negative (two's complement). Algorithm: Invert all bits of the operand Add 1 to inverted operand

Example MOV AL, 5 ; AL = 05h NEG AL ; AL = 0FBh (-5) NEG AL ; AL = 05h (5)

SBB Subtract with Borrow. Algorithm: operand1 = operand1 - operand2 - CF

Example STC ; Set CF=1 MOV AL, 5 SBB AL, 3 AL =?

Distinguish between a carry and an overflow Arithmetic carry (CF) An arithmetic operation transfers the resulting sign bit (0 or 1) to CF. When the carry occurs with unsigned data, the result is invalid. When carry occurs with signed data, the result is valid

Distinguish between a carry and an overflow Arithmetic overflow (OF) Example: unsigned signed decimal 11110110 246 -10 + 10001001 37 -119 (1)01111111 127 (invalid) -129 (invalid) CF = 1 OF = 1

Note about DIV/ IDIV If divisor is a byte, a value must be greater than the left byte of the dividend (AH) If divisor is a word, its value must be greater than left word of the dividend (DX)

Define doubleword using words Assume, we have 13290147H, we can define this as: DDVAR DW 0147H DW 1329H

Practice 1. Open your browser and open this page: C:\emu8086\documentation\8086_instruction_set.html And C:\emu8086\documentation\8086_and_dos_interrupts.html 2. Open your emu8086 software 3. Cut and paste (or type) the following code (as shown in the next page) and save add.asm

page 60,132 TITLE AddPractice Add ; --------------------------------------------- STACK SEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACK ENDS ; ---------------------------------------------- DATASEG SEGMENT PARA 'Data' ; Please insert your data declaration here DATASEG ENDS CODESEG SEGMENT PARA 'Code' MAIN PROC FAR MOV AX, DATASEG MOV DS, AX MOV ES, AX ; Please insert your code here MOV AX,4C00H ;exit procedure INT 21H MAIN ENDP CODESEG ENDS END MAIN ;End of program

Practice 4. Define data: BIN1 DW 0147H DW 1329H BIN2 DW 02B3H DW 0241H SUM DW 0 DW 0 Write a program to add the doublewords beginning at BIN1 and BIN2 and store the result to doubleword beginning at SUM SUM= 156A03FAH