Lecture 4 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.

Slides:



Advertisements
Similar presentations
BINARY & HEX I/O. Binary input : read in a binary number from keyboard, followed by a carriage return. character strings of 1’s & 0’ we need to convert.
Advertisements

DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU
ICS312 Set 6 Operands. Basic Operand Types (1) Register Operands. An operand that refers to a register. MOV AX, BX ; moves contents of register BX to.
Computer Organization & Assembly Language
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Lecture 2 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
LAB Flow Control Instructions
Flow Control Instructions
Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#6)
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
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.
Topics Control Flow Structure – Conditional Jump – Unconditional Jump Control Flow Structures – IF-THEN – IF-THEN-ELSE – CASE Branches with Compound Conditions.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7)
Lecture 13 Basic I/O Interface
Lecture 3 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
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.
Overview of Assembly Language Chapter 4 S. Dandamudi.
Lecture 5 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
CET 3510 Microcomputer Systems Tech. Lecture 2 Professor: Dr. José M. Reyes Álamo.
Lecture 14 Basic I/O Interface Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
5. Assembly Language. Basics of AL Program data Pseudo-ops Array Program structures Data, stack, code segments.
(Flow Control Instructions)
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#9) By Dr. Syed Noman.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
21/11/2005CAP2411 Input & Output Instructions CPU communicates with the peripherals through I/O registers called I/O ports. There are 2 instructions, IN.
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.
10H Interrupt. Option 0H – Sets video mode. Registers used: – AH = 0H – AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:
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.
Control Structure vs. Assembly Language NASM. If-then-else If conditional then then_actions jump to endif else else_actions endif.
Assembly Language Lecture 2. Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT.
Lecture 6 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
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.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7) By Dr. Syed Noman.
Program Structure Example for Data Segment CRLF EQU 0DH, 0AH PROMPT DB 'Enter a digit between 0 and 9', 0 VAR1 DB ? ARRAY DW 1234h, 23h, 0FF54h.
Format of Assembly language
Presentation on Real Mode Memory Addressing
Lecture 4 Control Flow Structures (LOOPS)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
(The Stack and Procedures)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Introduction to Assembly Language
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
(Array and Addressing Modes)
(The Stack and Procedures)
Shift & Rotate Instructions)
Program Logic and Control
Program Logic and Control
Symbolic Instruction and Addressing
(Array and Addressing Modes)
High-level language structures
UNIT-II Assembly Language Programs Involving Logical
Chapter 6 –Symbolic Instruction and Addressing
(The Stack and Procedures)
Jump & Loop instructions
Chapter 7 –Program Logic and Control
Chapter 7 –Program Logic and Control
(Array and Addressing Modes)
Part VI Looping Structures
Presentation transcript:

Lecture 4 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Agenda Control Flow Structures – FOR Loop – WHILE Loop – REPEAT-UNTIL Loop Load Effective Address (LEA) Instruction Programming with Higher Level Structures

FOR Loop Write a program to display a row of 80 stars ‘*’ FOR 80 times DO display ‘*’ END_FOR MOV CX, 80; number of ‘*’ to display MOV AH, 2; char display function MOV DL, ‘*’; char to display TOP: INT 21h; display a star LOOPTOP; repeat 80 times Example 6-8: Assembly Language Programming

WHILE Loop Write a program to count the characters in an input line Initialize count to 0 Read a character WHILE character <> carriage_return DO count = count + 1 read a character END_WHILE MOV DX, 0; DX counts the characters MOV AH, 1; read char function INT 21h; read a char in AL WHILE_: CMP AL, 0DH; CR? JE END_WHILE INCDX INT 21h JMP WHILE_ END_WHILE: WHILE condition DO statements END_WHILE Example 6-9: Assembly Language Programming

REPEAT Loop REPEAT statements UNTIL condition Write a program to read characters until a blank/space is read REPEAT read a character UNTIL character is a blank MOV AH, 1; read char function REPEAT: INT 21h; read a char in AL CMP AL, ‘ ‘; a blank? JNEREPEAT; no, keep reading Example 6-10: Assembly Language Programming

Road Map Control Flow Structures – IF-THEN – IF-THEN-ELSE – CASE – FOR Loop – WHILE Loop – REPEAT-UNTIL Loop Load Effective Address (LEA) Instruction Programming with Higher Level Structures

Load Effective Address The LEA instruction loads any 16 bit register with the data address as determined LEA vs. MOV

Load Effective Address Example Write a program to exchange the contents of two memory locations Example 4-3: Intel Microprocessors – by Brey

LEA vs. OFFSET Directive OFFSET functions only with simple operands such as LIST. LEA functions with complex operands such as [DI], LIST [SI] etc. OFFSET is more efficient than LEA LEA BX, LIST is costly than MOV BX, OFFSET LIST

Example Write a program to print “Hello World”.MODEL SMALL.DATA PROMPTDB‘Hello world’, 0DH, 0AH, ‘$’.CODE.STARTUP ; initialize DS MOV MOV DS, AX ; display opening message MOV AH, 9; display string function LEA DX, PROMPT; get opening message INT 21h; display it.EXIT END

Road Map Control Flow Structures – IF-THEN – IF-THEN-ELSE – CASE – FOR Loop – WHILE Loop – REPEAT-UNTIL Loop Load Effective Address (LEA) Instruction Programming with Higher Level Structures

Programming with High Level Structures Problem – Prompt the user to enter a line of text. On the next line, display the capital letter entered that comes first alphabetically and the one that comes last. If no capital entered, display “No capital letters”. Type a line of text: THE QUICK BROWN FOX JUMPED First capital = B Last capital = X

Top-down Program Design Divide the problem into sub-problems 1.Display the opening message 2.Read and process a line of text 3.Display the results

Start the Program.MODEL SMALL.STACK100H.DATA PROMPTDB‘Type a line of text’, 0DH, 0AH, ‘$’ NOCAP_MSGDB0DH, 0AH, ‘No capitals $’ CAP_MSGDB0DH, 0AH, ‘First capital = ‘ FIRSTDB‘]’ DB‘ Last capital = ‘ $’.CODE.STARTUP Type a line of text: THE QUICK BROWN FOX JUMPED First capital = B Last capital = X Follows ‘Z’ in ASCII sequence Precedes ‘A’ in ASCII FIRSTLAST

Step 1. Display the opening message ; initialize DS MOV MOV DS, AX ; display opening message MOV AH, 9; display string function LEA DX, PROMPT; get opening message INT 21h; display it.DATA PROMPTDB‘Type a line of text’, 0DH, 0AH, ‘$’

Step 2: Read and Process a Line of Text Read a character WHILE character is not carriage return DO IF character is a capital letter (*) THEN IF character precedes first capital THEN first capital = character END_IF IF character follows last capital THEN last capital = character END_IF Read a character END_WHILE Line (*) is actually an AND condition: IF (‘A’ <= character) AND (character <= ‘Z’)

Step 2: Read and Process a Line of Text Read a character WHILE character is not carriage return DO IF character is a capital letter (*) THEN IF character precedes first capital THEN first capital = character END_IF IF character follows last capital THEN last capital = character END_IF Read a character END_WHILE Line (*) is actually an AND condition: IF (‘A’ <= character) AND (character <= ‘Z’) MOVAH, 1 INT 21h WHILE_: CMP AL, 0DH JEEND_WHILE CMPAL, ‘A’ JNGEEND_IF CMPAL, ‘Z’ JNLEEND_IF CMPAL, FIRST ; char < FIRST or ‘]’ JNLCHECK_LAST MOV FIRST, AL CHECK_LAST: CMPAL, LAST ; char > LAST or JNGEND_IF MOVLAST, AL END_IF: INT 21H JMPWHILE_ FIRST LAST

Step 3: Display The Results IF no capitals were typed THEN display “no capitals” ELSE display first capital and last capital END_ID MOVAH, 9; display string function CMPFIRST, ‘]’ JNECAPS; no, display results LEADX, NOCAP_MSG JMPDISPLAY CAPS: LEA DX, CAP_MSG DISPLAY: INT 21H.EXIT FIRST LAST

References Ch 6, Assembly Language Programming – by Charls Marut Section 4-3 of Intel Microprocessors – by Brey