Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Similar documents
Experiment N o 3 Segmentation and Addressing Modes

Experiment N o 3. Segmentation and Addressing Modes

Data Representation and Binary Arithmetic. Lecture 2

Lecture (09) x86 programming 8

Fundamentals of Programming (C)

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

CS-202 Microprocessor and Assembly Language

Experiment 3 3 Basic Input Output

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

Number System (Different Ways To Say How Many) Fall 2016

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Chapter 3. Information Representation

Fundamentals of Programming

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Chapter 2 Bits, Data Types, and Operations

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

Do not start the test until instructed to do so!

Chapter 2 Number System

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

Assembly Language: g Part III. First Semester 2013 Department of Computer Science Faculty of Science Chiang Mai University

Chapter 2 Bits, Data Types, and Operations

Number Representations

The Binary Number System

Do not start the test until instructed to do so!

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

EC 333 Microprocessor and Interfacing Techniques (3+1)

Oberon Data Types. Matteo Corti. December 5, 2001

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Chapter 2 Bits, Data Types, and Operations

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Chapter 2 Bits, Data Types, and Operations

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Fundamental Data Types

EEM336 Microprocessors I. Data Movement Instructions

Positional Number System

ASSIGNMENT 5 TIPS AND TRICKS

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Table of Contents Sleep Settings How to Configure the Scanner. 7 Chapter 2 System Setup

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Chapter 8. Characters and Strings

CSE 505 Lecture 8: Introduction to Assembly Language

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

Number Systems Base r

ASCII Code - The extended ASCII table

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

ORG ; TWO. Assembly Language Programming

Basic Assembly SYSC-3006

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

Chapter 2 Bits, Data Types, and Operations

Do not start the test until instructed to do so!

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

Intel 8086: Instruction Set

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

S-Series Sensor ASCII Protocol v8.1.0

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

Chemistry Hour Exam 2

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics

Variables and data types

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

Q. State and Explain steps involved in program development. [w-08, w-10, s-12, w-11]

EE 109 Unit 2. Binary Representation Systems

3.1. Unit 3. Binary Representation

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Chapter 1. Hardware. Introduction to Computers and Programming. Chapter 1.2

2D BARCODE SCANNER CA-SC-20200B

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

Kingdom of Saudi Arabia Ministry of Higher Education. Taif University. Faculty of Computers & Information Systems

The statement above assumes that the PCMAC.INC file is in the current directory. The full path of the file can also be given:

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

INT 21H and INT 10H Programming and Macros

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

APPENDIX B. ASSEMBLER DIRECTIVE SUMMARY

Connecting UniOP to Datalogic Barcode Readers

FD-011WU. 2D Barcode Reader User Guide V1.6CC

RS-232 Control of the Advantage EQ281/8, EQ282/8 and Advantage SMS200

Characters Lesson Outline

Hardware. ( Not so hard really )

OOstaExcel.ir. J. Abbasi Syooki. HTML Number. Device Control 1 (oft. XON) Device Control 3 (oft. Negative Acknowledgement

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

Acquirer JCB EMV Test Card Set

Introduction. Chapter 1. Hardware. Introduction. Creators of Software. Hardware. Introduction to Computers and Programming (Fall 2015, CSUS)

MOBILE THERMAL PRINTER

Lesson 1. Fundamentals of assembly language

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Under the Hood: Data Representation. Computer Science 104 Lecture 2

Transcription:

Experiment 3 Introduction: In this experiment the students are exposed to the structure of an assembly language program and the definition of data variables and constants. Objectives: Assembly language program structure Instructions and Directives Data representation Variable & constant declaration, ADD & SUB instructions Assembly Language Program Structure An assembly language program is a sequence of instructions and directives. A program consists of one statement per line. The general structure of an assembly language program follows the guidelines shown in the following table: TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program..stack This directive specifies the memory space reserved for the stack.data Assembler directive that reserves a memory space for constants and variables.code Assembler directive that defines the program instructions END Assembler directive that finishes the assembler program Instructions and Directives: Table 3.1: Assembly Language Program Structure Instruction: The format of an assembly instruction closely mirrors the structure of a machine instruction An instruction is meant for the processor. The assembler translates this instruction into machine code Statement syntax: Name operation operand(s) ;comment 1

Examples: Directive: MOV AX, BX ADD AX, MEM16 ; Load AX to prepare for multiplication ; AX = AX + MEM16 Pseudo-instructions or assembler directives are instructions that are directed to the assembler. They will affect the machine code generated by and will not be translated directly into machine code. Directives are used to declare variables, constants, segments, macros, and procedures as well as supporting conditional assembly Model Directive: The model determines the size of the code stack and data segments of the program. Each, of the segments is called a logical segment. Depending on the model used, the code and data segments may be in the same or in different physical segments as shown in table 3.2. In most of our programs, the model small is sufficient. The tiny model is usually used to generate command files (files with extension.com). This type of files is smaller in size than the executable files with extension.exe. Memory Model Size of Code and Data Code Data Note TINY 64KB 64KB Code + Data 64KB SMALL 64KB 64KB MEDIUM may be 64KB 64KB COMPACT 64KB may be 64KB LARGE may be 64KB may be 64KB no array 64KB HUGE may be 64KB may be 64KB arrays can be 64KB Stack Directive: Table 3.2: Memory Models Directive is.stack for stack segment Should be declared even if program itself does not use stack needed for subroutine calling (return address) and possibly passing parameters May be needed to temporarily save registers or variable content 2

Memory Segment: Directive =.Data All variables must be declared at this level All constants must be defined at this level A variable is declared by : DB, DW,.. A constant is defined using: the directive equ. Code Segment: The directive.code is used for code segment The program code resides here End of Program: The Directive End is used to tell the assembler that this is the end of the program source file. Note: The following sequence of instructions is always used at the beginning of a program to assign the data segment: MOV AX, @DATA MOV DS, AX This sequence may be replaced by the following directive:.startup which assigns both DATA and CODE segments, and hence the assembler will issue no warning. However, it should be noted that the program would start at address CS:0017H. The Startup directive occupies the bytes CS:0000 to CS:0017H..EXIT ically, the sequence used to terminate and exit to DOS MOV AH, 4CH INT 21H can be replaced by the.exit directive, which has exactly the same effect. 3

Data Representation: Numbers: 11011 decimal 11011B binary 64223 decimal -21843D decimal 1,234 illegal, contains a non-digit character 1B4DH hexadecimal number 1B4D illegal hex number, does not end with H FFFFH illegal hex number, does not begin with a digit 0FFFFH hexadecimal number Signed numbers are represented using 2 s complement notation Characters A character must be enclosed in single or double quotes: e.g. Hello, Hello, A, B The ASCII code is used to encode characters Examples: A has ASCII code 41H a has ASCII code 61H 0 has ASCII code 30H Line feed has ASCII code 0AH Carriage Return has ASCII code 0DH Back Space has ASCII code 08H Horizontal tab has ASCII code 09H Note: The value of a variable, the content of registers or memory is based on the programmer interpretation: AL = FFH represents the unsigned number 255 represents the signed number -1 (in 2 s complement) AH = 30H represents the decimal number 48 represents the character 0 BL = 80H represents the unsigned number +128 represents the signed number -128 4

Variable Declaration Each variable has a type Based on its definition, a variable is assigned a memory location The location is defined by its address and number of bytes. Different data definition directives for different size types of memory o DB o DW o DD o DQ o DT define byte define word define double word (two consecutive words) define quad word (four consecutive words) define ten bytes (five consecutive words) Each pseudo-op can be used to define one or more data items of given type. Byte Variables The following directive defines a variable of size byte: Examples: o Var_name DB initial value o a question mark (?) place in initial value leaves variable non-initialized I DB 4 define variable I with initial value 4 J DB? Define variable J with no initial value Name DB Course allocate 6 bytes for the variable Name K DB 5, 3, -1 allocates 3 bytes K 05 Word Variables: 03 FF The following directive defines a variable of size word: o Var_name DW initial value o a question mark (?) place in initial value leaves variable non-initialized 5

Examples: I DW 4 J DW -2 K DW 1ABCH L DW 01 I J K L 04 00 FE FF BC 1A 31 30 Double Word Variables The following directive defines a variable of size double word: o Var_name DD initial value I DD 1FE2AB20H J DD -4 I J 2 AB E 1 FF F F 6

Constant Definition: The EQU pseudo-op is used to assign a name to a constant Syntax: Cst_name EQU Cst_Value No memory allocated for EQU names. Makes assembly language easier to understand E xamples: Example 1: MOV DL, 0AH Can be replaced by: LF EQU 0AH MOV DL, LF Example 2: MSG DB Type your name Can be replaced by: PROMPT EQU Type your name MSG DB PROMPT 7

ASCII Table binary MSN 0000 0001 0010 0011 0100 0101 0110 0111 LSN hex 0 1 2 3 4 5 6 7 0000 0 NUL 0 00 DLE 16 10 SP 0001 1 SOH 1 01 XON (DC1) 17 11! 0010 2 STX 2 02 DC2 18 12 " 0011 3 ETX 3 03 XOFF (DC2) 19 13 # 0100 4 EOT 4 04 0101 5 ENQ 5 05 0110 6 ACK 6 06 0111 7 BEL 7 07 1000 8 BS 1001 9 HT 1010 A LF 1011 B VT 1100 C FF 1101 D CR 1110 E SO 1111 F SI 8 08 9 09 10 0A 11 0B 12 0C 13 0D 14 0E 15 0F DC4 20 14 $ 32 20 0 48 30 @ 64 40 P 80 50 ` 33 21 1 49 31 A 65 41 Q 81 51 a 34 22 2 50 32 B 66 42 R 82 52 b 35 23 3 51 33 C 67 43 S 36 24 4 52 34 D 68 44 T 83 53 c 84 54 d NAK 21 15 % 37 25 5 53 35 E 69 45 U 85 55 e SYN ETB 22 16 & 38 26 6 54 36 F 23 17 ' CAN 24 18 ( EM SUB ESC FS GS RS US 25 19 ) 26 1A * 27 1B + 28 1C, 29 1D - 30 1E. 31 1F / Example on the use of the ASCII table 70 46 V 86 56 f 39 27 7 55 37 G 71 47 W 87 57 g 40 28 8 56 38 H 72 48 X 88 58 h 41 29 9 57 39 I 42 2A : 43 2B ; 58 3A J 73 49 Y 89 59 i 74 4A Z 59 3B K 75 4B [ 44 2C < 60 3C L 76 4C \ 45 2D = 61 3D M 77 4D ] 46 2E > 62 3E N 78 4E 47 2F? 63 3F O 79 4F ^ _ 90 5A j 91 5B k 92 5C l 96 60 p 97 61 q 98 62 r 99 63 s 100 64 t 101 65 u 102 66 v 103 67 w 104 68 x 105 69 y 106 6A z 107 6B { 108 6C 93 5D m 109 6D } 94 5E n 95 5F o 110 6E ~ Character Column # Row # Code (H) Code (binary) a 6 1 61H A 4 1 41H β E 1 E1H % 2 5 25H Table 3.3: Using the ASCII table: 111 6F 112 70 113 71 114 72 115 73 116 74 117 75 118 76 119 77 120 78 121 79 122 7A 123 7B 124 7C 125 7D 126 7E DEL 127 7F 8

ADD & SUB instructions: Type Inst. Example Meaning O F Flags Affected S Z A F F F P F C F ADD ADD AX, 7BH AX AX + 7B * * * * * * Addition ADC ADC AX, 7BH AX AX + 7B +CF * * * * * * INC INC [BX] [BX] [BX]+1 * * * * * - DAA DAA? * * * * * SUB SUB CL,AH CL CL AH * * * * * * SBB SBB CL,AH CL CL AH CF * * * * * * Subtraction DEC DEC DAT [DAT] [DAT] 1 * * * * * - DAS DAS? * * * * * NEG NEG CX CX 0 CX * * * * * * Table 3. 4:: Summary of add and sub instructions 9

Exercises Program 1: A Case Conversion Program Write a program that prompts the user to enter a lowercase letter, and on next line displays another message with letter in uppercase. Enter a lowercase letter: a In upper case it is: A Title Program Small to Upper Case Conversion.Model Small.Stack 100.DATA CR EQU 0DH LF EQU 0AH MSG1 DB Enter a lower case letter: $ MSG2 DB CR, LF, In upper case it is: Char DB?, $.CODE.STARTUP ; initialize data segment LEA DX, MSG1 ; display first message MOV AH, 9 INT 21H MOV AH, 1 ; read character INT 21H SUB AL, 20H ; convert it to upper case MOV CHAR, AL ; and store it LEA DX, MSG2 ; display second message and MOV AH, 9 ; uppercase letter INT 21H.EXIT ; return to DOS END Program 2: A Case Conversion Program 2 Write a program that prompts the user to enter an uppercase letter, and on the next line displays another message with letter in lowercase. Program 3: Write a program that reads small characters from the keyboard and converts them online to uppercase ones. Use the following to make your program loop. Also use function 08 to read a character without echo. next: Loop next ; read character ; convert ; display 10