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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Addressing modes The way in which an operand is specified is called the Address Mode.
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.
1/2002JNM1 AL 00 Immediate Addressing Mode Mov AL, 3CH AL 3C.
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.
Irvine, Kip R. Assembly Language For Intel-Based Computers TYPE and SIZE Operators TYPE –returns the size, in bytes of a single element of a data label.
Lect 3: Instruction Set and Addressing Modes. 386 Instruction Set (3.4) –Basic Instruction Set : 8086/8088 instruction set –Extended Instruction Set :
Addressing modes – 1 The way in which an operand is specified is called the Address Mode.
Lecture 2 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 4:
1 Lecture 4: Data Transfer, Addressing, and Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Target Processor Directives , When using.386, the program can only run on 386 and above processors.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Symbolic Constants Equal-Sign Directive Calculating.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Flow Control Instructions
Kip Irvine: Assembly Language for Intel-Based Computers
Irvine, Kip R. Assembly Language For Intel-Based Computers.data string db "This is a string." COUNT = ($–string) ; calculate string length.code mov cx,COUNT.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
Lect 4: Instruction Set and Addressing Modes. 386 Instruction Set (3.4)  Basic Instruction Set : 8086/8088 instruction set  Extended Instruction Set.
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.
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
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.
Faculty of Engineering, Electrical Department,
Strings, Procedures and Macros
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.
Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by.
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.
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
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.
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
Review of Assembly language. Recalling main concepts.
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.
Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags.
Assembly Language Lecture 2. Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT.
Internal Programming Architecture or Model
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
1 Using the Assembler Chapter – 4(A). 2 Exchanging Two Variables title Exchange Two Variables (Exchange.asm).model small.stack 100h.data value1 db 0Ah.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7) By Dr. Syed Noman.
Stack Operations Dr. Hadi AL Saadi.
Assembly language programming
Format of Assembly language
Presentation on Real Mode Memory Addressing
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Data Transfers, Addressing, and Arithmetic
16.317: Microprocessor System Design I
Microprocessor and Assembly Language
Microprocessor and Assembly Language
(The Stack and Procedures)
UNIT: 2 INSTRUCTION SET OF 8086.
Symbolic Instruction and Addressing
Chapter 4: Instructions
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)
Symbolic Instruction and Addressing
Flow Control Instructions
Assembler Directives end label end of program, label is entry point
Chapter 6 –Symbolic Instruction and Addressing
(The Stack and Procedures)
Intel 8086.
By Nasser Halasa Assembly Language.
Presentation transcript:

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 –Write instructions to load each number into DL and display it on the console. (use Int 21h, function 4Ch to display the byte in DL on the console) Explain why the output is “1234”

Procedure Get templatetemplate Make necessary changes. Assemble and Link using make16 Run and debug using Codeview

Template for Assembler Programs (Spring, 2003) ;*********************************************** ; Program Name * ;*********************************************** title INCLUDE Irvine16.inc ;*********************************************** ; Data Segment * ;***********************************************.data ; put data here ;*********************************************** ; Code Segment * ;***********************************************.code main proc mov mov ds,ax ;initialize DS register ; put code here mov ah,4Ch ;int 21h function 4c int 21h ;return to DOS main endp end main ;end of program

Defining Data.data List byte 31h, 32h, 33h, 34h

Writing to Standard Output Interrupt 21h (MS-DOS Services) –Function 2 Write character stored in DL to standard out (Appendix C-2, page 652 of Irvine 4 th Edition) We have to get the data from memory to register DL and then Mov ah,2; use the mov instruction to ; store the interrupt 21h ; function number in register AH Int 21h; use int instruction to process ; interrupt

Moving Data from Memory to DL MOV destination, source –The source operand is unchanged! –Both operands must be the same size –Both operands cannot be memory operands! –CS and IP cannot be destination operands –An immediate value cannot be moved to a segment register

MOV Instruction MOVreg, reg MOVmem, reg MOVreg, mem MOVmem, imm MOVreg, imm In real address mode –MOVr/m16, sreg –MOVsreg, r/m16

Moving Data from Memory to DL Mov dl, list; AL = 31h Mov dl, list + 1; AL = 32h Mov dl, list + 2; AL = 33h Mov dl, list + 3; AL = 34h

Using Direct-Offset Operands The data in list (31h, 32h, 33h, 34h) can be accessed using the label (list). Putting brackets around the source operand does not affect the outcome. They are not required by MASM. –List+1 == [List+1] Use List+2, List+4, etc… for WORD lists Use List+4, List+8, etc… for DWORD lists

Title Writing_1234_to_Screen (1234_2.ASM) INCLUDE irvine16.inc.data array db 31h,32h,33h,34h;use db to define each element as 1 byte.code mainproc the address of the data into the DS register movah,2;int 21 function 2 displays the character in DL movdl, array;copy 1st byte of array to dl int21h movdl, array+1;copy 2nd byte to dl - uses direct-offset to access list elements int 21h movdl, array+2;copy 3rd byte to dl int21h movdl, array+3;copy 4th byte to dl int21h movax, 4c00h;terminate program and return to DOS int21h mainendp endmain

Can INC instruction be used to access different elements of the list ? The INC instruction adds 1 to a single operand –INC reg/mem So can we use –INC array (example program)example program No! The only practical way to handle an array or list is to use a register as a pointer and change the register value to point to different elements of the list.

OFFSET Operator Returns the offset of a data label. In protected mode, an offset is always 32- bits long In real mode, an offset is always 16-bits long.

Change Code to … Mov bx, OFFSET list Mov dl, [bx] Int 21h Inc bx Mov dl, [bx] Int 21h Inc bx NOTE: Inc works because the data is bytes. Use: –Add bx,2 ;for word size data –Add bx,4 ;for Doubleword size data

LOOP Instruction LOOP provides a simple way to repeat a block of statements a specific number of times. CX (ECX) is automatically used as the counter LOOP destination is put at the end of a section of code to be repeated. First, CX is decremented, then CX is compared to zero. If CX is not equal to zero a jump is taken to the label identified by destination.

INCLUDE irvine16.inc.data array db 31h,32h,33h,34h;use db to define array COUNT = ($-array);The $ operator gives the value of the location counter..code mainproc the address of the data segment movds, into the DS register movbx, offset array;the offset operator returns the 16-bit offset of a label movcx, COUNT;set up cx register as a counter register. movah, 02;use function 2 of int 21h - display char stored in dl on screen LP1:movdl, [bx];LP1 is a label int21h incbx loopLP1;decrement cx; if cx not =0,loop back to label LP1. movax, 4c00h int21h mainendp endmain