Assembly Language Lecture 2. Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT.

Slides:



Advertisements
Similar presentations
Program.(08) Write a program Divide 5 by 2 and display answer value and remainder value. 1 Store 5 into AL 2 Store BL into 2 3Divide AL Into BL 4Store.
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.
Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents.
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.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Memory model ModelDescription SMALLCode in one segment Data in one segment MEDIUMCode in > 1 segment Data in one segment COMPACTCode in one segment Data.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
ICS312 Set 11 Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External.
8.4 Instruction Execution Times TOBIN PROC FAR SUB AX,AX MOV DX,AX MOV CX,4 NEXTD: PUSH CX SUB BP,BP MOV CX,4 GETNUM: RCL BX,1 RCL BP,1 LOOP GETNUM.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#6)
Assembly Programming Timothy C. Rice Jr., MIT. OUTLINE Basic Structure Exit to Dos Print Character Clear Screen Change BG & FG Color Set Curser Location.
Lecture 6 Assembler Directives. 2  Code generation flow  Assembler directives—Introduction  Segment control  Generic segment (SEGMENT, RSEG)  Absolute.
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.
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.
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7)
Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External 2. The type.
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.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
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.
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.
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
Multiplication and Division Instructions & the 0Ah function.
ICS312 Set 14 MACROS. Macros The program structure is similar to that for procedures. As for procedure names, macro names represent a group of instructions.
Chapter Five–80x86 Assembly program development Principles of Microcomputers 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 1.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by.
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.
L AB 2. P ROGRAM STRUCTURE The assembly language program consist of code, data and stack. Data segment: contains all the variable definition..Data Code.
21/11/2005CAP2411 Input & Output Instructions CPU communicates with the peripherals through I/O registers called I/O ports. There are 2 instructions, IN.
Software Interrupt Instruction ‘int’ A ‘int’ instruction is like a special kind of subroutine call. Will discuss details later ‘int’ stands for INTERRUPT.
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:
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h.
B ASIC INSTRUCTIONS. I NTRODUCTION There are over a hundred instructions in the instruction set for the 8086 CPU; there are also instructions designed.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
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
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Lecture 4 Control Flow Structures (LOOPS)
Microprocessor and Assembly Language
Computer Organization & Assembly Language
(The Stack and Procedures)
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
(The Stack and Procedures)
Chapter 4 –Requirements for coding in Assembly Language
Symbolic Instruction and Addressing
Chapter 4 –Requirements for coding in Assembly Language
Morgan Kaufmann Publishers Computer Organization and Assembly Language
INTRODUCTION ABOUT ASSEMBLY
Assembler Directives end label end of program, label is entry point
Chapter 6 –Symbolic Instruction and Addressing
(The Stack and Procedures)
By Nasser Halasa Assembly Language.
Procedures & Macros Introduction Syntax Difference.
Presentation transcript:

Assembly Language Lecture 2

Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT Instruction

Program Structure Assembly language programs consists of the following program segments: Code. Data. Stack. Each program segment is translated into a memory segment by the assembler.

Program Structure - Memory Models The size of code and data a program can have is determined by specifying a memory model using the.MODEL directive. Syntax:.MODELmemory_model ModelDescription SMALLcode in 1 segmentdata in 1 segment MEDIUMcode > 1 segmentdata in 1 segment COMPACTcode in 1 segmentdata > 1 segment LARGEcode > 1 segmentdata > 1 segment no array larger than 64k bytes HUGEcode > 1 segmentdata > 1 segment arrays may be larger than 64k bytes

Program Structure - Memory Models The appropriate model is SMALL, unless there is a lot of code or data..MODEL directive should come before segment definitions. A segment is 2 16 (64 k)

Program Structure - Stack Segment The purpose of the stack segment declaration is to set aside a block of memory (the stack area) to store the stack. The stack area should be big enough to contain the stack at its maximum size. Syntax:.STACKsize ; where size is an optional number that specifies ; the stack area size in bytes. Example:.STACK100H ; sets aside 100H bytes for the stack area. ; (reasonable size for most applications). If size is omitted, 1KB is set aside for the stack area.

Program Structure - Data Segment A program’s data segment contains all the variable definitions. Constant definitions are often made here as well. (they may be placed elsewhere in the program since no memory allocation is involved). To declare a data segment, we use the directive.DATA, followed by variable and constant declarations. Example:.DATA WORD1DW 2 MSGDB ‘this is a message’

Program Structure - Code Segment The code segment contains a program’s instructions. Syntax:.CODEname ; where name is an optional name of segment. There is no need for a name in a SMALL program, However, the assembler will generate an error. Inside a code segment, instructions are organized as procedures.

Program Structure - Code Segment The simplest procedure definition is: name PROC ; name: is the name of the procedure. ; body of the procedure ; PROC & ENDP: are pseudo-ops that name ENDP ; delineate the procedure Example of a code segment definition:.CODE MAIN PROC ; main procedure instructions MAIN ENDP ; other procedures go here

Program Structure - A General Form of a.SMALL model program.MODEL SMALL.STACK 100H.DATA ; data definitions go here.CODE MAIN PROC ; instructions go here MAIN ENDP ; other procedures go here ENDMAIN

Input and Output Instructions There are two categories of I/O service routines: The Basic Input/Output System (BIOS) routines. The DOS routines.

INT Instruction To invoke a DOS or BIOS routine, the INT (interrupt) instruction is used. Format: INT interrupt_number where interrupt_number is a number that specifies a routine.

INT 21h INT 21h may be used to invoke a large number of DOS functions. A particular function is requested by placing a function number in the AH register and invoking INT 21h. Some of the functions are: INT21h functions expect input values to be in certain registers and return output values in other registers. Function numberRoutine 1single-key input 2single-character output 9character string output

INT 21h To invoke the routine, the following instructions should be executed: MOV AH,1; input key function INT 21H; ASCII code in AL Function 1: Single-Key Input Input: AH = 1 Output: AL = ASCII code if character key is pressed = 0 if non-character key is pressed

INT 21h To invoke the routine, the following instructions should be executed: MOV AH, 2; display character function MOV DL, '?'; character is '?' (or any other character) INT 21H; display character Function 2: Display a character or execute a control function Input: AH = 2 DL = ASCII code of the character Output AL = ASCII code of the character

INT 21h Function 2 may be used to perform control functions. If DL contains the ASCII code of a control character, INT 21h causes the control function to be performed. The principal control characters are : ASCII code (Hex)SymbolFunction 07HBELbeep (sounds a tone) 08HBSbackspace 09HHTtab 0AHLFline feed (new line) 0DHCR carriage return (start of current line)

INT 21h To invoke the routine, the following instructions should be executed: MOV MOV DS, AX MOV AH, 9; display string function LEA DX, MSG; get message (Load Effective Address) INT 21H; display string Function 9: Display a string Input: AH = 9 DX = offset address of string. The string must end with a '$' character A program containing a data segment should begins with these two instructions

INT 21h To invoke the routine, the following instructions should be executed: MOV AH, 4CH; DOS exit function INT 21H; exit to DOS Function 4CH: Returning control to DOS Input: AH = 4CH

TITLE P1: ECHO PROGRAM.MODEL SMALL.STACK 100H.CODE MAIN PROC ; display prompt MOV AH,2; display character function MOV DL,'?'; character is '?' INT 21H; display it ; input a character MOV AH,1; read character function INT 21H; character in AL MOV BL,AL; save it in BL ; go to new line MOV AH,2; display character function MOV DL, 0DH; carriage return INT 21H; execute carriage return MOV DL, 0AH; line feed INT 21H; execute line feed ; display character MOV DL, BL; retrieve character INT 21H ; and display it ; return to DOS MOV AH, 4CH; DOS exit function INT 21H; exit to DOS MAIN ENDP END MAIN Echo Program

Print String Program TITLE P2: PRINT STRING PROGRAM.MODEL SMALL.STACK 100H.DATA MSG DB'HELLO!$'.CODE MAIN PROC ; initialize DS MOV get data segment MOV DS,AX ; initialize DS ; display message LEA DX,MSG ; get message MOV AH,9 ; display string function INT 21H ; display message ; return to DOS MOV AH, 4CH ; DOS exit function INT 21H ; exit to DOS MAIN ENDP END MAIN