Control Structure vs. Assembly Language NASM. If-then-else If conditional then then_actions jump to endif else else_actions endif.

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.
Writing and reading files. Creating a file on a disk Get a file handle from system Use INT 21H function 3C to create a directory entry for the file Use.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
Chapter 7 Programming with DOS and BIOS Function Calls Objectives: The use of DOS and BIOS function call How to read the PC’s keyboard How to send text.
Chapter 9 Using Disks and Files Objectives: The difference between Floppy and Hard Disks What the Boot Sector is for What the File Allocation Table is.
Flow Control Instructions
Kip Irvine: Assembly Language for Intel-Based Computers
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 ;
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 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Programming the Microprocessor A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
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.
1 Screen and Keyboard Operations Suthida Chaichomchuen
Multiplication and Division Instructions & the 0Ah function.
Lecture 4 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Practical Session 11 Computer Architecture and Assembly Language Input &Output (I/O)
Arithmetic Flags and Instructions
(Flow Control Instructions)
File I/O MS-DOS Interrupt 21h has many functions dealing with file and directory I/O services. Both MS-DOS and MS_Windows use 16- bit integers called HANDLES.
8086 Microprocessor Interrupts By: Vijay Kumar. K Reference From Slide Share.
Writing and Reading Files Methods for processing disk files File Control Blocks (FCBs) –Supported by DOS –Can address drives and filenames.
Lecture Set 4 Programming the 8051.
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:
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.
4. Kernel and VGA ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  None.
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.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
ICS 312 SET 10 Multiplication & Division & input using function 0Ah.
2/20/2016CAP 2211 Flow Control Instructions. 2/20/2016CAP 2212 Transfer of Control Flow control instructions are used to control the flow of a program.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 13: 16-Bit MS-DOS Programming Interrupts (c) Pearson Education, All rights reserved.
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.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA 1 Assembly Language Programming.
Practical Session 11 Computer Architecture and Assembly Language Input &Output (I/O)
Format of Assembly language
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Additional Assembly Programming Concepts
Microprocessor and Assembly Language
Lecture 4 Control Flow Structures (LOOPS)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
Assembly IA-32.
Assembly Language Programming Part 2
Microprocessor and Assembly Language
Symbolic Instruction and Addressing
CS-401 Computer Architecture & Assembly Language Programming
Shift & Rotate Instructions)
Program Logic and Control
Program Logic and Control
Symbolic Instruction and Addressing
Computer Architecture and Assembly Language
Unit:08 Software Interrupts
High-level language structures
UNIT-II Assembly Language Programs Involving Logical
Jump & Loop instructions
Chapter 7 –Program Logic and Control
By Nasser Halasa Assembly Language.
Chapter 8: Instruction Set 8086 CPU Architecture
Chapter 7 –Program Logic and Control
Part VI Looping Structures
Presentation transcript:

Control Structure vs. Assembly Language NASM

If-then-else If conditional then then_actions jump to endif else else_actions endif

Ex. If-Then-Else If AL < 0xA then DL= AL + ’0’ Else DL = AL - 0xA +’A’ EndIf MOVDL, AL CMP AL, 0xA JAETenUp ADDDL,’0’ JMPEndIf TenUp: ADDDL,’A’-0xA EndIf:

Repeat-Until Loop at lease one time Repeat Statements … Until Condition is True

Ex. Repeat-Until BX <- 1 AX <- 1 CX <- 5 Repeat BX <- BX + 2 AX <- BX * AX CX <- CX – 1 Until CX=0 = MOV BX, 1 MOV AX, 1 MOV CX, 5 RLOOP: ADD BX, 2 MUL BX DEC CX JNZ RLOOP = 0x289B

While loop Check the condition before the loop While Condition is true Statements …

Ex. While-loop BX <- 1 AX <- 1 CX <- 5 While CX > 0 BX <- BX + 2 AX <- BX * AX CX <- CX – 1 = MOV BX, 1 MOV AX, 1 MOV CX, 5 WLOOP: CMP CX, 0 JE EndLOOP ADD BX, 2 MUL BX DEC CX JMP WLOOP EndLOOP:

For loop Loop in the specific range with automatic decrease index. Loop instruction with CX register.

Ex. For loop “Loop” Instruction will automatically decrease CX and loop if CX is not zero CX <- number of loop StartLoop: Instructions … Loop StartLoop MOV BX, 1 MOV AX, 1 MOV CX, 5 FLOOP: ADD BX, 2 MUL BX LOOP FLOOP 5 Loop

Frequently used routines Int 21h DOS Service routines

Int 21h’s format Usage: Reg AH is used as function number you wish to perform. Ex. To call function 1 int 21h to get a character from keyboard. FirstMOV AH, 01 INT 21H

Keyboard input with echo Usage : AH <- 1 Return: AL -> character from standard input device waits for keyboard input from STDIN and echoes to STDOUT Returns 0 for extended keystroke, then function must be called again to return scan code if Ctrl-Break is detected, INT 23 is executedCtrl-BreakINT 23

Display a character Usage: AH <- 02 DL <- character to output Return: Returns nothing outputs character to STDOUT backspace is treated as non-destructive cursor left if Ctrl-Break is detected, INT 23 is executedCtrl-BreakINT 23

Direct console input without echo Usage: AH <- 07 Return: AL -> character from STDIN waits for keyboard input until keystroke is ready character is not echoed to STDOUT returns 0 for extended keystroke, then function must be called again to return scan code ignores Ctrl-Break and Ctrl-PrtSc - see INT 21,1

Console input without echo Usage: AH <- 08 Return: AL -> character from STDIN returns 0 for extended keystroke, then function must be called again to return scan code waits for character from STDIN and returns data in AL if Ctrl-Break is detected, INT 23 is executed

Display a string end with “$” Usage: AH <- 09 DS:DX <- pointer to string ending in "$“ Returns: Returns nothing outputs character string to STDOUT up to "$“ backspace is treated as non-destructive if Ctrl-Break is detected, INT 23 is executedCtrl-BreakINT 23

Read keyboard into a buffer Usage AH <- 0A DS:DX <- pointer to input buffer of the format: | max | count | BUFFER (N bytes) | | ` input buffer | ` number of characters returned (byte) ` maximum number of characters to read (byte) e.g. DB 0x5, 6 dup (?)

Read keyboard into a buffer Returns since strings can be pre-loaded, it is recommended that the default string be terminated with a CR N bytes of data are read from STDIN into buffer+2 max buffer size is 255, minimum buffer size is 1 byte chars up to and including a CR are placed into the buffer beginning at byte 2; Byte 1 returns the number of chars placed into the buffer (extended codes take 2 characters) DOS editing keys are active during this call INT 23 is called if Ctrl-Break or Ctrl-C detected

Clear Keyboard Buffer & Invoke Function Usage: AH <- 0C AL <- 01, 06, 07, 08 or 0A (INT 21 input functions) Return: See return values from INT 21, AL where AL is 1, 6, 7, 8 or A Main function is to clear the input buffer and call INT 21h with the specified function (in AL)

Create file using handle Usage: AH <- 3C CX <- file attribute (see FILE ATTRIBUTES)FILE ATTRIBUTES DS:DX <- pointer to ASCIIZ path name Return: CF = 0 if successful / =1 if error AX = files handle if successful = error code if failure (see DOS ERROR CODES)DOS ERROR CODES if file already exists, it is truncated to zero bytes on opening

Open file using handle Usage: AH <- 3D AL <- open access mode 00 read only, 01 write only, 02 read/write DS:DX <- pointer to an ASCIIZ file name Return: AX = file handle if CF not set = error code if CF set (see DOS ERROR CODES)DOS ERROR CODES

Read File or Device Using Handle Usage: AH <- 3F BX <- file handle CX <- number of bytes to read DS:DX <- pointer to read buffer Return: AX = number of bytes read is CF not set = error code if CF set (see DOS ERROR CODES ) DOS ERROR CODES read specified number of bytes from file into buffer DS:DX when AX is not equal to CX then a partial read occurred due to end of file if AX is zero, no data was read, and EOF occurred before read

Write To File or Device Using Handle Usage: AH <- 40h BX <- file handle CX <- number of bytes to write, a zero value truncates/extends the file to the current file position DS:DX <- pointer to write buffer Return: AX = number of bytes written if CF not set = error code if CF set (see DOS ERROR CODES ) DOS ERROR CODES if AX is not equal to CX on return, a partial write occurred this function can be used to truncate a file to the current file position by writing zero bytes

Close File Using Handle Usage: AH <- 3E BX <- file handle to close Return: AX = error code if CF set (see DOS ERROR CODES)DOS ERROR CODES if file is opened for update, file time and date stamp as well as file size are updated in the directory handle is freed

Delete File Usage: AH = 41h DS:DX = pointer to an ASCIIZ filename Return: AX = error code if CF set (see DOS ERROR CODES) marks first byte of file directory entry with E5 to indicate the file has been deleted. The rest of the directory entry stays intact until reused. FAT pointers are returned to DOS FAT documented as not accepting wildcards in filename but actually does in several DOS versions

Rename File Usage: AH <- 56h DS:DX <- pointer to old ASCIIZ path/filename ES:DI = pointer to new ASCIIZ path/filename Return: AX = error code if CF set (see DOS ERROR CODES)DOS ERROR CODES supports full pathnames and allows renaming files across directories and in DOS 3.x allows renaming subdirectories does not support use of wildcards unless invoked from via INT 21,5D in which case error code 12h is returnedINT 21,5D unpredictable result may occur if an opened file is renamed

Move File Pointer Using Handle Usage: AH <- 42h AL <- origin of move: 00 = beginning of file plus offset (SEEK_SET) 01 = current location plus offset (SEEK_CUR) 02 = end of file plus offset (SEEK_END) BX <- file handle CX <- high order word of number of bytes to move DX <- low order word of number of bytes to move Return: AX = error code if CF set (see DOS ERROR CODES)DOS ERROR CODES DX:AX = new pointer location if CF not set seeks to specified location in file

Ex. Show files’ contents org 100h jmp start fh dw 0 buf db 0 start:mov bl,[0x80] cmp bl,0 jz noparam xor bh,bh add bl,0x81 ;set filename mov byte [bx],00; mov ah,0x3d ;open mov al,0x00 mov dx,0x82 ;param int 21h jc error ;if flag set mov [fh],ax;save file handle next: mov bx,[fh];get file handle mov ah,0x3f;read file mov cx,1 ;1 byte mov dx,buf int 21h jc error ;check error cmp ax,0 ;ax=0 :: eof jz done mov ah,2 ;display a char mov dl,[buf] int 21h jmp next

Ex. Show files’ contents done: mov ah,0x3e;close file int 21h int 20h errorMsg db "There is an error$" error:mov ah,09 mov dx,errorMsg int 21h int 20h noParamMsg db "Please enter a filename$" noparam:mov ah,09 mov dx,noParamMsg int 21h int 20h Save -> show.asm nasm show.asm -oshow.com Usage: Show.com readme.txt

Q & A