28
Microprocessor and Interfacing Techniques SSUET/QR/114 Telecommunication Engineering Department Sir Syed University of Engineering & Technology 1 Laboratory Exercise 1(a) Objective: Introducing the BGC- 8088 Microprocessor training system. Salient features. Hardware specifications. Software architecture. Description: The BGC Micro-engineer V3.4 is an 8088 microprocessor training system. It contains hardware and software to expand its functions and applications. It provides user an inexpensive and useful learning tool for the 8088 microprocessor. Salient Features of BGC-8088 Micro-engineer V3.4 Trainer (i) Hardware: 8088-2 CPU, 4.77 MHz clock, with 8 MHz option.8K SRAM and 16K EPROM with wired socket for additional 24K SRAM and 16K EPROM. 1MB RAM is optional. Keyboard: Large size, 56 alphanumeric and ASCII symbol keys. On-board LCD display. An external 80 x 24 monochrome monitor can be used with a Hercules card. Built in standard Centronics printer interface. RS-232 interface. Two IBM PC or compatible expansion slots. Status ports to display keyboard status as Caps Lock, Ins, and Ctrl-P. In addition, a speaker is built in for user application. Parallel control interfaces: Three 8-bit I/O ports(8255), three timers(8254), and five interrupt signals (8259A). An area on the main board is reserved for circuit designs and experiments. Switching power supply: +5V, +5V, +12V, +12V and GND. (ii) Software: 8088 assembler and dis-assembler. Assembly language coding. Memory commands. D-display, M-move, C-Compare, E-edit and F-fill. Display and / or modify the contents of registers.

Microprocessor and Interfacing Techniques SSUET/QR/114 ...umartalha.weebly.com/uploads/8/3/8/2/8382263/micro2015...Microprocessor and Interfacing Techniques SSUET/QR/114 Telecommunication

  • Upload
    others

  • View
    6

  • Download
    1

Embed Size (px)

Citation preview

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    1

    Laboratory Exercise 1(a) Objective: Introducing the BGC- 8088 Microprocessor training system.

    Salient features.

    Hardware specifications.

    Software architecture. Description: The BGC Micro-engineer V3.4 is an 8088 microprocessor training system. It contains hardware and software to expand its functions and applications. It provides user an inexpensive and useful learning tool for the 8088 microprocessor.

    Salient Features of BGC-8088 Micro-engineer V3.4 Trainer

    (i) Hardware:

    8088-2 CPU, 4.77 MHz clock, with 8 MHz option.8K SRAM and 16K EPROM

    with wired socket for additional 24K SRAM and 16K EPROM. 1MB RAM is

    optional.

    Keyboard: Large size, 56 alphanumeric and ASCII symbol keys. On-board LCD

    display. An external 80 x 24 monochrome monitor can be used with a Hercules card.

    Built in standard Centronics printer interface.

    RS-232 interface.

    Two IBM PC or compatible expansion slots.

    Status ports to display keyboard status as Caps Lock, Ins, and Ctrl-P. In addition,

    a speaker is built in for user application.

    Parallel control interfaces: Three 8-bit I/O ports(8255), three timers(8254), and

    five interrupt signals (8259A).

    An area on the main board is reserved for circuit designs and experiments.

    Switching power supply: +5V, +5V, +12V, +12V and GND.

    (ii) Software:

    8088 assembler and dis-assembler. Assembly language coding.

    Memory commands. D-display, M-move, C-Compare, E-edit and F-fill.

    Display and / or modify the contents of registers.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    2

    Single step program execution and debug.

    Breakpoint debug, for setting up to 10 breakpoints for program debugging.

    Numerical systems conversions and calculations.

    Download / Upload from / to external system.

    RS-232 driver routine.

    Keyboard driver routine.

    Printer driver routine.

    Hercules card driver routine.

    LCD driver routine.

    Hardware specifications of BGC-8088 Micro-engineer V3.4 Trainer

    CPU: 8088-2 CPU runs at 4.77 MHz. However, a clock rate of 8 MHz can be achieved

    by using a 24 MHz crystal oscillator.

    RAM: The system provides 32K RAM, addresses from 00000H to 07FFFH, with 00000H to 00FFFH for system program and 0100H to 07FFFH for user applications.

    ROM: The system provides ROM, addresses from F8000H to FFFFFH, with FC000H to FFFFFH for BIOS and F8000H to FBFFFH for user applications.

    Keyboard: It has 56 keys which include alphanumeric A-Z and 0-9 special ASCII symbols.

    Display: An On-board 40x2 LCD module or a *)x24 monochrome monitor can be

    used. The later requires a Hercules card.

    Printer interface: BGC-8088 provides a standard Centronics printer interface.

    The connection cable is the same as those used in IBM PCs.

    RS-232 interface. The 8250 controls the RS-232 interface. It can be programmed for

    baud rate, data bit, and stop bit.

    I/O expansion slot: The signals are compatible with the IBM PC expansion slot, but

    no DMA function is provided.

    Status port: The status port is used to display keyboard statuses such as Caps Lock,

    Ins, and Ctrl-P. A correspondent LED is lighted when the function is enabled. In

    addition, it provides the speaker interface to generate sound.

    Parallel control interface: Three IC’ s are used to provide parallel controls. They are

    8255- three 8-bit I/O ports, 8254, - three timers, and 8259A – five interrupt signals. Power supply: +5V, -5V, +12V, -12V and GND are used in this system.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    3

    Software architecture of BGC-8088 Micro-engineer V3.4 Trainer The BGC-8088 is designed to allow the user to access system programs and apply these programs to user’ s own applications. In addition, an I/O driver routine is available for each I/O device. These routines can be called by issuing an interrupt instructions in the user’ s application programs. The following diagram illustrates the software architecture.

    System Program User Program

    I/O Drivers

    Hardware

    System Commands:

    The system commands provide

    Memory management

    Program control

    Numeric operation / conversion

    I/O control.

    Communication.

    I/O Drivers:

    The I/O drivers of BGC-8088 provide the software interface between the system and I/O devices.

    RS-232 driver.

    Keyboard driver

    Printer driver

    Hercules card driver

    LCD display driver

    Return to BIOS (system)

    Assignment: Note down the IC part numbers used in the BGC-Trainer.

    Download the datasheets of each IC.

    Write summary of each IC.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    4

    Laboratory Exercise 1 (b)

    Objective:

    Introducing the syntax and use of the system commands of BGC trainer.

    Description:

    The system commands can be divided into the following groups according to their functions.

    Memory Management Commands.

    Assembler Commands.

    Numerical Operation Commands.

    Program Execution Commands.

    Each command begins with a command letter followed by 1 to 3 operand parameters. The parameters of system commands are described below. consists of two portions. Segment address: Offset address.

    Segment registers, CS, DS, ES and SS are often used to hold a segment address. Segment address can be omitted, but the offset value must be indicated.

    indicates an operation section of memory.

    The syntax for range must be one of th efollowing.

    N is the starting address, and could contain both segment and

    offset addresses.

    is the ending address and contain only offset address. The addresses in must be in the same segment. The value of must be greater or equal to the offset address

    in

    a 4 digit hexadecimal number.

    a 2 digit hexadecimal number.

    a set of characters included in single or double quotation marks.

    a series of s, s, and /or s, separated by commas.

    Note:

    Hexadecimal numerical system is used throughout the experiments (unless otherwise specified).

    The suffix ‘H’ can be omitted.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    5

    Memory Management Commands

    C Compare the contents of two blocks of memory. D Display the contents of memory.

    E Edit (Write) data into memory.

    F Fill the memory with a value.

    M Move the contents of memory.

    Command C: Compare the contents of two blocks of memory Command syntax C,

    indicates the source area

    is the starting address of the target memory block.

    If any mismatch is found, the system displays both the source and target addressees and their contents.

    Command D: Display the contents of memory

    Command syntax D

    It will display the contents of a specified memory location.

    The ASCII codes for this value will also displayed.

    tells the D command what range of memory to display.

    If range is not specified, then the default starting address is set to the location following the last address used by a previous D command.

    It there is no previous D commands, then the default starting address is 0100:0000.

    The default length of display is 80H.

    Command E: Edit (Write) data into memory Command syntax E

    It is used to write data into memory.

    When E command is used without a parameter; the system displays the and its contents, a byte of data.

    The user then types in a new byte of data, (two hexadecimal digits), to replace it.

    If is pressed, the next address can be edited.

    Memory can be edited until is pressed to exit the E command.

    Command F: Fill the memory with a value

    Command syntax F

    It is used to change the contents of a block of memory to a certain sequence of values.

    The memory locations specified in are filled with the values specified in .

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    6

    Command M: Move the contents of memory

    Command syntax M,

    It move the contents of a block of memory specified in from one place to another.

    The starting address of the destination is specified in .

    There are two different procedures for moving memory.

    1. The first is used when the block occurs before the destination address.

    2. The second is used when the destination start address is less than the source start address.

    .

    The destination occurs before the source If the starting address of is greater than , data is moved from the starting address of to in ascending order.

    The source occurs before the destination

    If the starting address of the is smaller than , then the bytes of the are moved to the destination in descending order. This means that the last byte in the is moved to the last location in the destination first.

    Assembler Commands A Assemble a program.

    U Disassemble a program

    I Insert an instruction in a program.

    Command A: Assemble a program

    Command syntax A []

    It is used to program with the 8088 assembly language.

    Since memory space on the BGC-8088 is restricted, the assembler is limited in comparison to a

    PC macro assembler, these limitations are listed below. The assembler translate instructions into machine code and stores them in memory

    immediately after they are entered.

    There is no linking function. There is no macro function. Names and labels cannot be used to define the locations of the data segment or the code

    segment.

    NOTE: and may be overlapped.

    However, overlapping will destroy the original memory contents

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    7

    Command U: Disassemble a program Command syntax U []

    It is used to disassemble assembly language instructions into machine code.

    is used to select a block of memory to disassemble.

    If is not specified, then the system will start immediately after the final address of the

    last U command. If no U command have been executed, the default starting address is CS: IP, which is set to

    0100:0000 after power-on.

    The default length is 20H.

    Command I: Insert instruction into a program

    Command syntax I []

    The I and A command can both be used to enter 8088 assembly language instructions.

    However, these two commands differ in how memory is handled.

    The A command overwrites the contents (machine codes) of the specified memory,

    While I command only pushes the contents back one location without erasing them.

    The INS key is used in toggle mode.i.e by pressing it will insert instructions into memory. As long as the INS LED is ON, the only way to leave insert mode is to press the INS key once again.

    Numerical Operation Commands

    B Decimal to binary conversion.

    H Compute the sum and difference of 2 hexadecimal numbers. J Decimal to hexadecimal conversion.

    S Hexadecimal to decimal conversion.

    V Binary to decimal conversion.

    Command B: Converting decimal to binary

    Command syntax B

    The range of decimal numbers on the BGC-8088 is 0 to 4294967295 (i.e. 65535 x 65535)

    Negative numbers are not considered.

    The binary representation for numbers in this range requires up to 32 bits.

    When the binary values is displayed, the leading zeroes are omitted, and B is appended to denote that the number is binary.

    If the decimal number is greater than 4294967295, it can not be converted into binary.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    8

    Command J: Converting decimal to hexadecimal

    Command syntax J

    The range of decimal numbers is from 0 to 4294967295, up to 8 digits are needed in the hexadecimal representation of a decimal number.

    As with the B command, the leading zeros or the result are not displayed and an H is suffixed to denote that the number is in hexadecimal.

    Command S: Converting hexadecimal to decimal

    Command syntax S

    The range of decimal numbers is from 0 to FFFFFFFF, and no negative numbers are considered.

    Therefore, the maximum decimal number is 4294967295.

    In the result, the leading zeros are not displayed and a D appended to denote decimal representation.

    If the input value is non-hexadecimal or greater than FFFFFFFF, no conversion is executed and an error message is issued.

    Command V: Converting binary to decimal

    Command syntax V

    The range of decimal numbers is from 0 to 11111111111111111111111111111111 (32 bits)

    Negative numbers are not considered.

    Therefore, the decimal result will not exceed 4294967295.

    In the result the leading zeros are not displays and a D is used to denote decimal representation.

    Command H: Calculate the sum and difference

    Command syntax H,

    If the sum is greater than FFFF the carry is discarded.

    Only 16 bits (4 hexadecimal digits) of the result are displayed.

    If is smaller than , a borrow is used to execute subtraction.

    Program Control Commands

    G Execute program

    R Display or modify the contents of registers.

    T Trace program execution.

    Command G: Execute program

    Command syntax G[=],[, ... ]

    The ‘ =’ sign in the above syntax indicates that a parameter will be given.

    If this symbol is not used, then the system assumes that any parameters are break points.

    specifies the beginning address of the program to be executed.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    9

    f it is not present, execution will start at the default value, which is the current CS: IP.

    tells the program results to determine whether the program runs as expected.

    Up to 10 break points are allowed.

    Multiple break points make debugging easier when the program contains flow control instructions, such as JNZ, JC, JNE etc.

    If no break point is set, control will not return to the user, until the program execution is completed.

    Command R: Check / change the register contents

    Command syntax R[=]

    The R command is used to check or change the contents of the 14 register in the BGC-8088 .

    It can be used to dump the register contents, or to display and modify the register contents.

    These functions can be described in the following ways.

    R: Display the register contents

    If there is no specified, the R command is used to dump all the register contents to the screen.

    The registers are displayed in the following order:

    AX, CX, DX, BX, SP, BP, SI, DI, ES, CS, SS, DS, IP and FG.

    R: : Display and modify the register contents.

    After executing this command, the name and contents of the specified register are displayed.

    The use can then modify the register contents, or press the key to display the next register in the order mentioned above.

    To exit this command Q or continuous to press until all the registers have been displayed.

    RF: Display and modify the contents of the FG register

    The RF command displays the current status of each flag.

    The definition of the flag register is as follows.

    Flag Register:

    MSB LSB

    15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

    XX XX XX XX OF DF IF TF SF ZF XX AF XX PF XX CY

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    10

    Flags Name Bit = 1 Bit = 0

    OF Overflow OV NV

    DF Direction DN UP

    IF Interrupt EI DI

    TF Trap (Single step)

    SF Sign N G PL

    ZF Zero ZR NZ

    AF Auxiliary Carry AC NA

    PF Parity PE PO

    CY Carry CY NC

    Values of each flag Bits.

    Command T: Trace program execution Command syntax T[=], []

    The T command provides single step program execution.

    It executes one instruction at a time, and displays the register contents after each

    instruction.

    is the beginning address for program execution.

    If it is not specified, the program starts at the current address of CS:IP.

    defines the number of instructions to be executed.

    The default value is 1.

    The P command is used, then Enter, at instruction LOOP to pass through the looping.

    Assignment:

    Write atleast first 8-bytes of each Memory Management Command.

    Assemble the following code and fill the table.

    Logical Address Opcode Assembly code comments

    MOV AX, 0200H ;

    MOV BX, 0400H ;

    ADD AX, BX ;

    Give answer for the following questions regarding above results:

    Why the values 0200H and 0400H are written as 0002 and 0004 respectively?

    Write the number of bytes each instruction taken and also the value of IP register.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    11

    Laboratory Exercise 2

    Objective: To understand the basic assembly language instructions and performing basic arithmetic operations. To understand how the Half-Adder, Full Adder, Half-Subtractor, Full Subtractor, Multiplier and Divisor circuits are implemented as assembly instructions. Theory: Addition: Half-Adder is implemented using the instruction ADD. No carry-in but carry-out may occur. Full Adder is implemented using the instruction ADC. Both carry-in and carry-out may occur. (a) Program to add two 32 bit numbers using ADC (add with carry) command.

    Assembly Language Program:

    Address Data/Code Mnemonics Comments

    -------:0100 MOV AX,1111 -------: MOV BX,2000 -------: MOV CX,3000 -------: MOV DX,4000 -------: ADD AX,CX -------: ADC BX,DX

    Result :____________________________________________________________ Also write the flags affected.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    12

    Subtraction: Half-Subtractor is implemented using the instruction SUB.

    Full Subtractor is implemented using the instruction SBB. Subtraction is implemented using 2’s complement method. Steps involved in subtraction

    1. Takes 2’s complement of subtrahend 2. Add it to the minuend. 3. Invert the carry.

    If CY=0 then result is a positive number Else if CY=1 then result is a negative number and stored in 2’s complement.

    (b) Program to subtract two 32 bit numbers using SBB (Subtract With Borrow ) command.

    Assembly Language Program:

    Address Data/Code Mnemonics Comments

    -------:0100 MOV AX,3000 -------: MOV BX,2000 -------: MOV CX,1000 -------: MOV DX,4000 -------: SUB AX,DX -------: SBB BX,CX

    Result :____________________________________________________________ Also write the flags affected.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    13

    Multiplication: Multiplication Operand 1 Operand 2 Result Byte x byte AL Register or memory AX Word x word AX Register or memory DX AX Word x byte AL=byte, AH=0 Register or memory DX AX

    (c) Program to multiply two numbers store in registers BL and CL, and store the result in register DX.

    Assembly Language Program:

    Address Data/Code Mnemonics Comments

    -------:0100 MOV BL, 05 -------: MOV CL, 10 -------: MOV AL, CL -------: MUL BL -------: MOV DX, AX

    Result :____________________________________________________________

    Also write the flags affecred.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    14

    Division: Division Numerator Denominator Quotient Remainder Byte / byte AL=byte, AH=0 Register or memory AL AH Word / word AX=word,DX=0 Register or memory AX DX Word / byte AX=word Register or memory AL AH DW / word DXAX=DW Register or memory AX DX (d) Program to divide two numbers store in registers BL and CL,

    Assembly Language Program:

    Address Data/Code Mnemonics Comments

    -------:0100 MOV BL, 05 -------: MOV CL, 10 -------: MOV AH, 00 -------: MOV AL, CL -------: DIV BL

    Result: _____________________________________________

    Also write the flags affected.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    15

    Laboratory Exercise 3 (a)

    Objective:

    Introducing DEBUG programming (at command prompt using PC).

    Description:

    DEBUG is a program included in the MS-DOS and PC-DOS operating systems that allows the programmer to monitor a program’s execution closely for debugging purposes. Specifically, it can be used to examine and alter the contents of memory, to enter and run programs, and to stop programs at certain points in order to check or even change data. Student will learn

    How to enter and exit DEBUG,

    How to code, run and debug programs

    How to look at machine code

    How to examine and alter the contents of registers and memory,

    How to examine and alter the FLAG register

    Entering and Exiting DEBUG:

    To enter and exit the DEBUG, simply type its name at the DOS level:

    C:\> DEBUG

    To quit the DEBUG, type Q at the DEBUG prompt and enter

    Q

    C:\>

    Coding, Running and Debugging the programs:

    To assemble a program, write the following at DEBUG prompt

    A

    Example: - A 100

    Address Data/Code Mnemonics Comments

    0100:0100 MOV BL, 05 ;Load data 05 in register BL 0100: MOV CL, 10 ;Load data 10 in register CL 0100: MOV AL, CL ; Position data 0100: MUL BL ;Multiplying 0100: MOV DX, AX ; Storing product in register DX

    NOTE:

    DEBUG is not case-sensitive.

    It is assumed in the above instruction that DEBUG program is on the drive C

    After enter key pressed, the DEBUG prompt “-“ will appear on the following line.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    16

    To run or execute the instructions, write the following at DEBUG prompt

    G “G stands for GO”

    Assemble the above cod to multiply two numbers and run the instructions using G command.

    Various forms of the Go Command

    -G

    -G = start address

    -G = start address ending address

    -G address

    To debug a program, T (Trace) command is used which is a powerful debugging tool

    T < = starting address > < number of instructions>

    Also, Debug will inform any error by indicating “^Error” just under the faulty instruction.

    Looking at the machine code , the Unassemble command:

    The unassembled command displays the machine code in memory along with their equivalent Assembly language instructions. The command can be given in either format shown below.

    U < starting address > < ending address >

    U < starting address > < L number of bytes >

    Get the above cod to multiply two numbers be unassembled using the U command at DEBUG prompt.

    Examine and alter the contents of registers, FLAG registers and memory:

    Using the following commands at the DEBUG prompt can examine and alter the contents of

    memory registers and FLAG registers,

    F Fills a block of memory with data

    F

    F

    D Dumps or Displays contents of memory on the screen

    D

    D E Enter command, examines/alters the memory contents

    E

    E

    R check the contents of Registers

    R Rf ( for FLAG registers)

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    17

    Laboratory Exercise 3 (b)

    Objective:

    To learn how to create and assemble an executable Assembly Language Programming

    using Assembler and Linker programs.

    Description:

    The three steps to be followed to create an executable assembly language program are listed as under

    Steps Input Program Output

    1. Edit the program Keyboard Editor myfile.asm

    2. Assemble the program myfile.asm TASM or MASM myfile.obj

    3. Link the program myfile.obj TLINK or LINK myfile.exe

    Where, .asm, .obj, and .exe are the extension meaning assembler, object and executable file respectively.

    Directives:

    .model (memory models)

    Memory Models Code segment size Data segment size

    Small 64kb 64kb

    Medium Can exceed 64kb 64kb

    Compact 64kb Can exceed 64kb

    Large Both can exceed 64kb (single data array can’t exceed 64kb)

    Huge Both can exceed 64kb (single data array can exceed 64kb)

    .stack 100h

    Stack memory reserved 100 bytes

    .data

    Data segment starts

    .code

    Code segment starts

    As it is obvious from the above description that a program is to be typed in by using an editor,

    like Notepad (in windows) or Edit (in DOS) with the extension “.asm”, it is then presented to

    an assembler program such as TASM (Turbo Assembler) or MASM (Microsoft’s Macro

    Assembler) in the following manner, (assuming that you are working on the COMMAND

    PROMPT)

    C:\> MASM myfile.asm < return >

    If no errors found in the program, MASM will generate an object file. This object file is to be

    presented to the TLINK (Turbo Linker) or LINK as

    C:\> LINK myfile.obj < return >

    If no errors occur, this will generate an executable file ready to be run stand-alone.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    18

    The executable file just created can be analyzed or debugged using DEBUG utility, the

    method will be

    C:\> DEBUG myfile.exe < return > The desired DEBUG commands can then be used.

    ACTIVITY:

    Write, Run and Analyze a program that adds 5 bytes of data and saves the result. The data

    should be the following numbers:

    25, 12, 15, 1F, 2B

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    19

    Laboratory Exercise 4

    Objective: To learn how to implement loop in assembly language. To learn how a software program affects the hardware signals and their connections.

    Theory: LOOP Command: The Loop is implemented by using the command “LOOP” followed by the lable of the instruction where to jump to. The maximum number of iterations (repetitions) is defined in the register CX. The LOOP instruction first decrements the value of count defined in register CX and checks the value of CX register. If the CX register contains a non-zero value the loop continues otherwise the loop stops. For example, following code will add 1 in the value contained in register AL for 10 times.

    SUM:

    MOV CX, 10 MOV AL, 0 ADD AL, 1 LOOP SUM

    ;CX=max. count value i.e.; 10 ;Initializing AL with zero ;Add 1 to AL ;DEC CX and JNZ SUM

    The alternate of the LOOP instruction can be a combination of two commands DEC and JNZ. To demonstrate this the above code can be written as:

    SUM:

    MOV CX, 10 MOV AL, 0 ADD AL, 1 DEC CX JNZ SUM

    ;CX=max. count value i.e.; 10 ;Initializing AL with zero ;Add 1 to AL ;CX=CX-1 ;If zero flag is not set i.e.; CX != 0 then jump to SUM

    It is also to be noted that the count initialization for the CX value is done outside the loop. Loops can also be used to insert delays in a Program. In this lab exercise we will require to turn on/off sequentially the LEDs interfaced on the BGC-trainer. To make the sequence visible we need to put a delay in between. Communicating with the hardware through software: To communicate with the hardware (Input/Output devices), 8088 microprocessor is provided with the IN and OUT commands. Each I/O device while interfacing to the microprocessor is assigned a port address through which it can access the processor and can be accessed by the processor. Requirement for IN command: DX=Port address, AL=value from the port IN command sequence: MOV DX, portAddress IN AL, DX Requirement for OUT command: DX=Port address, AL=value to the port OUT command sequence: MOV DX, portAddress MOV AL, value OUT DX, AL

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    20

    Description: The program controls the input signals SD0, SD1 and SD2.

    When one of these signals is low (L) or logic “0” the corresponding LED is turn ON.

    By adjusting the level of the input signals, the program can turn each LED OFF or ON at any time.

    In this program, the LEDs are turned ON and OFF in sequence to make them blink.

    The frequency of blinking cycle is determined by the contents of the CX register.

    Changing the value in the CX register changes the blinking frequency.

    Assembly Language Program:

    Address Data/Code Mnemonics Comments

    -U0,1b 0100:0000 BA70FF MOV DX,FF70 0100:0003 BOFE MOV AL,FE 0100:0005 EE OUT DX,AL 0100:0006 B9401F MOV CX,1F40 0100:0009 E2FE LOOP 0009 0100:000B B0FD MOV AL,FD 0100:000D EE OUT DX,AL 0100:000E B9401F MOV CX,1F40 0100:0011 E2FE LOOP 0011 0100:0013 B0FB MOV AL,FB 01000015 EE OUT DX,AL 0100:0016 B9401F MOV CX,1F40 0100:0019 E2FE LOOP 0019 0100:001B EBE3 JMP 0000 -g

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    21

    Laboratory Exercise 5 (a)

    Objective:

    Using MASM/TASM learn how to use different BIOS and DOS Interrupt Services.

    Description:

    There are some extremely useful subroutines within BIOS and DOS that are available to the user

    through the INT (Interrupt) instructions. The INT instruction is somewhat like a FAR CALL.

    When it is invoked, it saves the value of CS:IP for the next instruction to be executed and flags on

    the stack and load the value of the CS:IP of the ISR (Interrupt Service Routine), associated with

    the interrupt, from the IVT (Interrupt Vector Table). The INT instruction has the following format

    INT xx ;the interrupt number xx can be 00 to FFh

    This makes 256 interrupts in 80x86 microprocessors. Of these 256 interrupts, two are widely used

    namely, INT 21H (DOS) and INT 10H (BIOS). Each of them can perform number of functions.

    Various functions of INT 21H and INT 10H are selected by the value put in the AH register,

    To display character → function 2 with int 21h

    To display string → function 9 with int 21h

    To clear the screen → function 6 with int 10h

    To set the cursor → function 2 with int 10h

    Download the documents regarding int 10h and int 21h from the course website.

    http://www.ee322.tk.

    Activity 1:

    Write and run an Assembly language program to display “Hello World!”

    Activity 2:

    Write and run an Assembly language program to clear the screen and then set the cursor at desired

    location on the screen and display “Hello World!”

    Activity 3: Write and run an Assembly language program to clear the screen and then set the cursor at desired

    location on the screen and display the table of any number from 2 to 10.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    22

    Laboratory Exercise 5 (b)

    Objective:

    To demonstrate string handling in assembly language.

    Description: String: A series of data words (or bytes) that reside in consecutive memory locations Examples: move, scan, compare Some commands use for string handling

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    23

    Activity 1:

    Write and assemble a program in assembly language that scans the name “Mr. Gones” and

    replaces the “G” with the letter “J”.

    Activity 2:

    Write and assemble a program in assembly language that scan the input string and determine if it

    has letter “O” in it.

    Activity 3:

    Write and assemble a program in assembly language which compare the input string with a pre

    defined string (password) and displays “Access Granted” on matching and displays “Access

    Denied” if both the strings do not match.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    24

    Laboratory Exercise 6(a) Objective:

    Introduction of Emulator (Emu8086) and stepper Motor

    Materials:

    Emulator (EMU8086)

    Web Site: www.emu8086.com

    Description:

    Emulator:

    Emulator runs programs on a Virtual PC, this completely blocks your program from accessing real

    hardware, such as hard-drives and memory, since your assembly code runs on a virtual machine,

    this makes debugging much easier.

    Everything for learning assembly language in one pack! Emu8086 combines an advanced source

    editor, assembler, disassembler, software emulator (Virtual PC) with debugger, and step by step

    tutorials. This program is extremely helpful for those who just begin to study assembly language.

    It compiles the source code and executes it on emulator step by step.

    Visual interface is very easy to work with. You can watch registers, flags and memory while your

    program executes. Arithmetic & Logical Unit (ALU) shows the internal work of the central

    processor unit (CPU).

    Virtual Devices

    Traffic Lights - Port 4 (word)

    The traffic lights are controlled by sending data to I/O Port 4.

    There are 12 lamps: 4 green, 4 yellow, and 4 red.

    You can set the state of each lamp by setting its bit:

    1 - the lamp is turned on.

    0 - the lamp is turned off.

    Only 12 low bits of a word are used (0 to 11), last bits (12 to 15) are unused.

    For example:

    MOV AX, 0000001011110100b

    OUT 4, AX

    http://www.emu8086.com/

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    25

    We use yellow hexadecimal digits in caption (to achieve compact view), here's a conversion:

    Hex - Decimal

    A - 10

    B - 11

    C - 12 (unused)

    D - 13 (unused)

    E - 14 (unused)

    F - 15 (unused)

    First operand for OUT instruction is a port number (4), second operand is a word (AX)

    that is written to the port. First operand must be an immediate byte value (0..255) or DX

    register. Second operand must be AX or AL only.

    If required you can read the data from port using IN instruction, for example:

    IN AX, 4

    First operand of IN instruction (AX) receives the value from port, second operand (4) is a

    port number. First operand must be AX or AL only. Second operand must be an

    immediate byte value (0,255) or DX register.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    26

    Stepper Motor - Port 7 (byte)

    The Stepper Motor is controlled by sending data to I/O Port 7.

    Stepper Motor is electric motor that can be precisely controlled by signals from a

    computer.

    The motor turns through a precise angle each time it receives a signal.

    By varying the rate at which signal pulses are produced, the motor can be run at different

    speeds or turned through an exact angle and then stopped.

    This is a basic 3-phase stepper motor, it has 3 magnets controlled by bits 0, 1 and 2. Other

    bits (3..7) are unused.

    When magnet is working it becomes red. The arrow in the left upper corner shows the

    direction of the last motor move. Green line is here just to see that it is really rotating.

    For example, the code below will do three clock-wise half-steps:

    MOV AL, 001b ; initialize.

    OUT 7, AL

    MOV AL, 011b ; half step 1.

    OUT 7, AL

    MOV AL, 010b ; half step 2.

    OUT 7, AL

    MOV AL, 110b ; half step 3.

    OUT 7, AL

    If you ever played with magnets you will understand how it works.

    If required you can read the data from port using IN instruction, for example: IN AL, 7

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    27

    Activity 1:

    Rotate the Stepper Motor one complete revolution clockwise.

    Activity 2:

    Rotate the stepper motor “N” times clockwise and “M” times counter clockwise, where N & M

    represents last two digits of your roll number.

    Activity 3:

    Write and assemble a program to run traffic lights module.

  • Microprocessor and Interfacing Techniques SSUET/QR/114

    Telecommunication Engineering Department

    Sir Syed University of Engineering & Technology

    28

    Laboratory Exercise 6(b)

    Objective:

    To perform some computation by using Assembly Language Programming.

    To generate Fibonacci series

    To generate BCD count

    Description:

    The Fibonacci Series is a sequence of numbers first created by Leonardo Fibonacci (fi-bo- na-chee) in 1202. It is a deceptively simple series, but its ramifications and applications are nearly

    limitless. It has fascinated and perplexed mathematicians for over 700 years, and nearly everyone

    who has worked with it has added a new piece to the Fibonacci puzzle, a new tidbit of information

    about the series and how it works. Fibonacci mathematics is a constantly expanding branch of

    number theory, with more and more people being drawn into the complex subtleties of Fibonacci's

    legacy. (do visit http://en.wikipedia.org/wiki/Fibonacci_number)

    The series is like

    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946,

    17711, 28657, 46368, 75025, 121393,

    In computing and electronic systems, binary-coded decimal (BCD) is an encoding for decimal numbers in which each digit is represented by its own binary sequence. Its main virtue is

    that it allows easy conversion to decimal digits for printing or display and faster decimal

    calculations. Its drawbacks are the increased complexity of circuits needed to implement

    mathematical operations and a relatively inefficient encoding – it occupies more space than a pure

    binary representation. In BCD, a digit is usually represented by four bits which, in general,

    represent the values/digits/characters 0-9.

    Activity 1:

    Write and run an Assembly language program to generate the Fibonacci series upto 233.

    Activity 2:

    Write and run an Assembly language program to generate two digit BCD up/down counts

    (00 – 999).

    http://en.wikipedia.org/wiki/Computinghttp://en.wikipedia.org/wiki/Electronicshttp://en.wikipedia.org/wiki/Numerical_digithttp://en.wikipedia.org/wiki/Bit