Artifact FLO1 2 ELab Learning Tools

Embed Size (px)

Citation preview

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    1/31

    E-laboratory Tool for Microprocessor Assembly Language

    Programming and its Applications

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    2/31

    Fundamental of Microprocessor

    Lab 0 Introduction to Intel 8086 Assembly Language

    Introduction

    Most programmers shy away from Assembler (or assembly language). People tend to

    consider it as a very difficult language to understand and use. This tutorial is the first in a series

    that will attempt to dismiss these misgiving about Assembler. It will demonstrate the tools that

    greatly simplify the authoring of Assembler, and show you how to integrate for microprocessor

    based project applications.

    First, what is Assembler?Assembler is the language of the processor. You can't get

    any lower level than this (except for possibly the actual byte values of the instructions). Everycommand (MOV, ADD, and so forth) is translated by an Assembler program directly into a

    number that, in turn, is fed to the processor on execution.

    The advantage of using Assembler over other languages is speed. Even with the modern

    compiler's ability to optimize code, the code that it produces would have trouble competing with

    the same written and optimized by hand in Assembler.

    Each processor has its own assembly language (syntax base on architecture of that

    microprocessor), and that is the main reason why one assembly program written for one

    microprocessor may not work with different microprocessor from different architecture class i.e.

    Intel program written for Windows operating system is not going to work with Mac running onMotorola microprocessor.

    Intel 8086 registers and flags

    Intel 8086 uses different types of register and flags for arithmetic operations and program

    flow control, but we will only talk about the most important registers and flags that will be

    essential for our introductory programming course.

    USE RESOURCES FROM EMU8086to write a brief description for each of the register and

    flag below:

    General data register:

    AXAH / AL

    BXBH / BL

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    3/31

    CXCH / CL

    DXDH / DL

    SI

    DI

    SP

    BP

    IP

    Flag registers (PSW) :

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    4/31

    1. Carry Flag (CF)- this flag is set to 1when there is an unsigned overflow. For example

    when you add bytes 255 + 1(result is not in range 0...255). When there is no overflowthis flag is set to 0.2. Parity Flag (PF)- this flag is set to 1when there is even number of one bits in result,

    and to 0when there is odd number of one bits.

    3. Auxiliary Flag (AF)- set to 1when there is an unsigned overflowfor low nibble (4

    bits).4. Zero Flag (ZF)- set to 1when result is zero. For non-zero result this flag is set to 0.

    5. Sign Flag (SF)- set to 1when result is negative. When result is positiveit is set to 0.

    (This flag takes the value of the most significant bit.)

    6. Trap Flag (TF)- Used for on-chip debugging.7. Interrupt enable Flag (IF)- when this flag is set to 1CPU reacts to interrupts from

    external devices.8. Direction Flag (DF)- this flag is used by some instructions to process data chains, whenthis flag is set to 0- the processing is done forward, when this flag is set to 1the

    processing is done backward.

    9. Overflow Flag (OF)- set to 1when there is a signed overflow. For example, when youadd bytes100 + 50(result is not in range -128...127).

    Instruction type : use EMU8086 tutorial to find out how these instruction work and write ashort description about each of the below instruction.

    http://www.emu8086.com/assembler_tutorial /reference.html

    Data movement instructionsare used to move or redirect data from register to register/memory

    MOV -

    PUSH -

    POP -

    LEA -

    Arithmetic and Logic instructionsare instructions that manipulate data arithmetically or

    logically

    ADD -

    SUB -

    INC -

    http://www.emu8086.com/assembler_tutorial%20/reference.htmlhttp://www.emu8086.com/assembler_tutorial%20/reference.htmlhttp://www.emu8086.com/assembler_tutorial%20/reference.html
  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    5/31

    DEC -

    AND -

    OR -

    XOR -

    NOT -

    SHL -

    SHR -

    Control Flow instructionsare used to control the flow of the program. The x86 processor

    maintains an instruction pointer (IP) register that is a 32 bit value indicating the location in the

    memory where the current instruction starts. Normally, it increments to point to the nextinstruction in memory begins after execution of instruction. The IP register cannot be

    manipulated directly, but it is updated implicitly by provided control flow instructions.

    When looking up these instructions, it is imperative to note how each of the condition take

    advantage of the different flag to achieve its operation.

    JMP -

    JE -

    JNE -

    JZ -

    JG -

    JGE -

    JL -

    JLE -

    Analysis

    Q1.If you have to write a program to count a number stored in AL register from 110, how

    would you do that? Just show simple drawing/writing of how your program would look in

    English.

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    6/31

    Example: We call this code Pseudo code and its just an idea of how you would attack the

    problem without thinking too much about the syntax of a program.

    PROGRAM TO ADD 1 to 14:

    MOVE 01h to AL register

    MOVE 0Eh (14 in decimal) to BL register

    ADD BL to AL (result will be stored in AL)

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    7/31

    Fundamental of Microprocessor

    Lab 1: Data Movement and Arithmetic Operation

    Data Movement Instructions

    These instructions are used to move data from one place to another. These places can beregisters, memory, or even inside peripheral devices. Some examples are:

    MOV AX, 13

    MOV BX, AX

    Arithmetic Instructions

    Arithmetic instructions take two operands: a destination and a source. The destination must be aregister or a memory location. The source may be either a memory location, or a register, or a

    constant value. Note that at least one of the two must be a register, because operations may not

    use a memory location as both a source and a destination. Examples are:

    ADD src, dest ADD AX, CXSUB dest, src SUB AX, BX

    MUL arg MUL CX

    SAMPLEprogram for arithmetic operation:

    ORG 0100H

    MOV AL,X ; Move X into AL

    MOV BL,02H ; Move 2 into BL

    MUL BL ; Multiply AL by BL, the result will be in AX

    MOV CX,AX ; Store the answer in CX

    MOV AL,Y ; Move Y into AL

    MOV BA,05H ; Move 5 into BL

    MUL BL ; Multiply AL by BL, the result will be in AX

    ADD AX,CX ; ADD first arithmetic result to second one

    MOV CL,W ; Move the dividend (W) into CL

    DIV CL ; Divide CL into AX, the result will be in AH,AL

    RET

    X DB 04H

    Y DB 03H

    W DB 02H

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    8/31

    Procedure

    Complete the following tasks.

    1.

    Launch the EMU8086 and enter the program provided in the above section.

    2. Try to run the program. It contains a bug (more exactly a typo), which is so trivial that

    even with no prior experience you should be able to correct it. Fix and re-assemble theprogram until no errors or warnings are left.

    3. After the program execute without any error, check the status and content of the registers

    after each single step execution.

    Analysis

    Q1. What is the different between ADD and MUL operation?

    Q2. What would be a situation when you use DB or DW as a data type declaration?

    Q3. What happens to the value in each register after each execution?

    Q4. What happens to IP (Instruction pointer) after each execution?

    Q5.What happens, if you change the value on line #3 from 02H to 0FFFH? Why?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    9/31

    Fundamental of Microprocessor

    Lab 2: Data Movement and Arithmetic Operation (Continued)

    Data Movement Instructions

    These instructions are used to move data from one place to another. These places can beregisters, memory, or even inside peripheral devices. Some examples are:

    MOV AX, 13

    MOV BX, AX

    Arithmetic Instructions

    Arithmetic instructions take two operands: a destination and a source. The destination must be a

    register or a memory location. The source may be either a memory location, a register, or aconstant value. Note that at least one of the two must be a register, because operations may not

    use a memory location as both a source and a destination. Some examples are:

    ADD src, dest ADD ax, cx

    SUB dest, src SUB ax, bxMUL arg MUL cx

    Procedure

    Complete the following tasks.

    1. Launch the EMU8086.

    2. Use the data movement and arithmetic operations from the last lab to complete thefollowing program.

    a.

    Convert 50 F to degree C, using following formula:C = (F - 32) x 5/9

    b. Convert 98 C to F, using following formula:

    F = C x 9/5 + 32

    2. After the program execute without any error, check the status and content of the registers

    after each single step execution.

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    10/31

    ORG 0100H

    MOV AL,F ; Load given F into ALMOV BL,20H ; Load 32 (20h) into BLSUB AL,BL ; Subtract 32 from FMOV BL,05H ; Move 5 into BL

    MUL BL ; Multiply AL by BL (5)MOV BL,09H ; Move 9 into BLDIV BL ; Divide AL by BLRET

    F DB 50

    ORG 0100H

    MOV AL,C ; Load given C into ALMOV BL, 09H ; Load 9 into BLMUL BL ; Multiply BL with AL ( 9 x 5)MOV BL,20H ; Load 32 (20h) into BLADD AL,BL ; add BL with ALMOV BL, 05H ; Load 5 into BLDIV BL ; Divide AL by BL ((Cx9)+ 32)/5RET

    C DB 98

    Analysis

    Q1. Can you use 32d (decimal) instead of 20h (hex) in the program? Try it !

    Q2.What if you have to do a lot of conversion, is there any better way or faster way of doing it?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    11/31

    Fundamental of Microprocessor

    Lab 3: Subroutine and Stack Operation

    Subroutine

    A subroutine is a set of code that can be branched to and returned from such a way that the codeis as if it were inserted at the point from which it is branched to.

    The branch to a subroutine is referred to as CALL and the corresponding branch back is knownas RETURN

    Subroutine provide the primary means of breaking the code in a program to modules

    Stack

    - It is a section of memory sets aside for storing return addresses.

    - It is also used to save the contents of registers for the calling program while a procedureexecutes

    - Another use of stack is to hold data or addresses that will be acted upon by a procedure.

    - PUSH and POP are 2 instructions that can operate on stack

    Procedure

    Complete the following tasks.

    1.

    Launch the EMU8086.2. We will be writing a program to calculate the sum of all resistance in a series and parallel

    circuit.

    3. Copy and paste the code into EMU 8086 and run the program in single step mode

    4. Make sure you open the stack window (should be on the bottom of emulator windows).5. After each single step execution, notice the content of AX, BX, CX, DX, IP, Stack

    Instructions used in this program: write the syntax for each of these instruction

    MOV - POP -

    ADD - DIV -

    PUSH -

    MUL -

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    12/31

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    13/31

    Fundamental of Microprocessor

    Lab 4: Subroutine (Continued)

    In this lab we will continue working with concept of assembly language subroutine. We alsogoing to introduce a new logical operation SHL and SHR

    SHL is simply shift left. In other words, say you've got the value 1 in AL. In binary that's

    00000001. If you SHL that 1 times, you get a value of 2 in AL or 00000010. Do it again and

    your bit(s) shift up by 1 more.

    SHL is cool because it's a quick way to multiply (amongst other things) a value by 2,4,8, etc

    because every time you SHL you double the value.

    SHRshift right will half your original value, making quick division a snap.

    Doing a "shl ax, cl" just takes the value in CL and shifts AX that many times.

    Procedure

    Complete the following tasks.

    1. Launch the EMU8086.

    2. We will be writing a program to calculate the sum of all resistance in a series and parallel

    circuit.

    3. Copy and paste the code into EMU 8086 and run the program in single step mode4. After the first single step execution write down the value to AL in decimal and binary

    (i.e. 3 = 00000011)

    5. Write down value of AL after the shl instruction got executed in decimal and binary.6. Did you notice what happen to the value compare to before shl instruction ?

    7. Finish program execution and note the final value of AX (AH and AL)

    8. What is the final value of AX in decimal? (remember that value shown in EMU is a hexvalue)

    9. What is the relationship between original AL value and final AX value?

    10.Can you guess what is the purpose of this program? Also can you write a comment after

    each line of code?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    14/31

    org 100h

    START: mov ax,x ; Please help write the commend for; for this program

    call x10call x10call x10

    ret

    x10 PROC

    shl ax,1mov bx,axshl ax,1

    shl ax,1add ax,bxretENDP

    x dw 5

    Analysis

    Q1.What if you change SHL AX, 1SHL AX, 2, what would happen to the result of the

    program and why?

    Q2.Can you write a program that will give you a square of a number by using SHL

    command?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    15/31

    Fundamental of Microprocessor

    Lab 5: Binary to Gray Converter

    Gray code:

    The problem withnatural binary codesis that, with real (mechanical) switches, it is very unlikelythat switches will change states exactly all the time. For example, in the two states (binary and

    gray) shown below, all three switches change state. In the brief period while all are changing, the

    switches will read some spurious position. Even withoutkeybounce,the transition might look

    like 011001101100. When the switches appear to be in position 001, the observercannot tell if that is the "real" position 001, or a transitional state between two other positions. If

    the output feeds into asequentialsystem (possibly viacombinational logic)then the sequentialsystem may store a false value.

    The Gray Code (reflected binary code) solves this problem by changing only one switch at a

    time, so there is never any ambiguity of position

    Dec Gray Binary

    0 000 000

    1 001 001

    2 011 010

    3 010 011

    4 110 100

    5 111 101

    6 101 110

    7 100 111

    Notice that state 7 can roll over to state 0 with only one switch change. This is called the "cyclic"property of a Gray code. In the standard Gray coding the least significant bit follows a repetitive

    pattern of 2 on, 2 off ( 11001100 );the next digit a pattern of 4 on, 4 off; and so forth.

    http://en.wikipedia.org/wiki/Binary_numeral_systemhttp://en.wikipedia.org/wiki/Binary_numeral_systemhttp://en.wikipedia.org/wiki/Binary_numeral_systemhttp://en.wikipedia.org/wiki/Keybouncehttp://en.wikipedia.org/wiki/Keybouncehttp://en.wikipedia.org/wiki/Keybouncehttp://en.wikipedia.org/wiki/Sequential_logichttp://en.wikipedia.org/wiki/Sequential_logichttp://en.wikipedia.org/wiki/Sequential_logichttp://en.wikipedia.org/wiki/Combinational_logichttp://en.wikipedia.org/wiki/Combinational_logichttp://en.wikipedia.org/wiki/Combinational_logichttp://en.wikipedia.org/wiki/Combinational_logichttp://en.wikipedia.org/wiki/Sequential_logichttp://en.wikipedia.org/wiki/Keybouncehttp://en.wikipedia.org/wiki/Binary_numeral_system
  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    16/31

    Hardware implementation:

    Exclusive OR gates were used to convert between Gray and Binary and Binary and Gray. What

    is the main different between the above circuits? Now we will implement Gray to Binary and

    Binary to Gray conversion using assembly language for 8086. Microprocessor is just a bigcombination of different logic gate, so we can leverage the benefit of having those logic gates

    simulate any hardware implementation of circuit via software.

    Procedure

    Complete the following tasks.

    1. Launch the EMU8086.

    2. Copy and Paste below code into EMU8086 code windows

    3. Single step execution and note content of AX and BX registers after each instruction4. Note value of BX after shr instruction

    5. Note the value of AX after program finish instruction and compare the value to the binary

    to gray conversion table. Did you get the right converted value?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    17/31

    ; Binary to gray converter

    org 0100h

    mov bx, x ; store number in bx registermov ax, bx ; copy content of bx to ax

    shr bx, 1 ; shift bx on binary position; to the right

    xor ax, bx ; XOR shifted bx to ax to get; result in gray code

    ret

    x dw 000bh

    Analysis

    Q1.Can you visualize and compare the software implementation and hardware implementation

    of Binary to Gray converter?

    Q2. Which Binary to Gray conversion is the easier of the two conversions?

    Q3.Can you now attempt to write an assembly program to convert the given Gray coded number

    to Binary?

    Hint: step 1: fix the left most digit as the same

    step 2: then add the digits from right to left

    org 0100h

    START: mov ax, gray ; store Gray coded number in axmov bx, ax ; copy value to bx (we do this

    ; so we can have a fixed number; to work with.

    shr ax, 1 ; shift ax to the right 1 binLOOP1: xor bx, ax ; XOR shifted ax to original(bx)

    shr ax, 1 ; keep shifting ax to the right; until the end of number

    jnz LOOP1 ; We know when we come to the

    ; end by zero flagmov ax, bx

    RET

    gray dw 0FE2Bh

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    18/31

    Fundamental of Microprocessor

    Lab 6: Flags and Control flow

    Assembly program will execute the code linearly down the memory address until it encounterprogram control flow instruction (JMP, JNZ, JG ..). We can use theseprogram control flow

    instructions to manipulate our program to branch out to different sections based on the condition

    of the flags that has been set by previous arithmetic or logical operations.

    Sample control flow structure for simple timer program

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    19/31

    Procedure

    Complete the following tasks.

    1.

    Launch the EMU8086.

    2. Copy and Paste below code into EMU8086 code windows3. Single step execution with the flags windows open

    4. Note value of AX,BX,CX after each execution

    5. Look up each of the control instruction on EMU8086 tutorial and write down thecondition of the branch. Compare those condition to the value of the flags when the jump

    happen.

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    20/31

    org 0100h

    START: mov cl, 03h

    LOOP_JNZ: dec cljnz LOOP_JNZ

    mov bl, 04hmov al, 04h

    LOOP_JZ: dec aldec blxor bl, aljz LOOP_JZ

    mov bl, 02hmov al, 06h

    LOOP_JG: dec alcmp al, bljg LOOP_JG

    mov bl, 06hmov al, 00h

    LOOP_JL: inc alcmp al, bljl LOOP_JL

    ret

    Analysis

    Q1.Can you write a program that use all of the branch conditions from EMU8086 tutorial and

    study how they work?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    21/31

    Fundamental of Microprocessor

    Lab 7: Flags and Control Flow (Continued)

    Pairs of ONEs

    Given abinary number 11001011. Write a program that count how many pairs (consecutive) of1 are in this binary string. For example, 11111111 has 7 total pair of 1, and 01101111 has 4 total

    pair of 1.

    HINT: Use combination of knowledge from last 2 previous labs about flags, program flow

    instruction and binary shift operation to help you with designing this program.

    SHL

    JZ

    JNC

    JNS

    JS

    Procedure

    Complete the following tasks.

    1. Launch the EMU8086.2. Copy and Paste below code into EMU8086 code windows

    3. Single step execution with the flags windows open

    4. Note value of AX and flags after each execution, and which operation cause value

    of AL to behave the way it did?5. What happens to the value of DX (more specifically DL) after each jump?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    22/31

    org 0100h

    MOV ax,x ; Move binary string into AXSTART: SHL ax,1 ; Shift content of AX to the left on

    ; positionJZ END ; The end of the string jump to ENDJC CALL PAIR_ONE ; If the Carry flag is 1, then call

    ; PAIR_ONE subroutineJNC START ; If the Carry flag is 0, then start

    ; the program againADD_ONE: INC dx ; INC DX after both condition are met

    JMP START ; Back to start and do it againEND: NOP ; This is the end of the main programret

    PAIR_ONE PROC ; Subroutine for comparison; after first stage (CF=1) is; met.

    JS CALL add_one ; If sign flag is a 1, then both; condition are met. Jump to; ADD_ONE:

    JNS START ; If sign flag is a 0, then back; to START to do it all over; again

    RETENDP

    x DW 0FFE6h ; Define string of 16 bits; binary number to be checked

    Analysis

    Q1.Is there any other alternate way (flags) we can write this program?

    Q2.Can you write a program that will give out the number of pair of 0s in a 16 bit string?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    23/31

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    24/31

    125 7

    365 534

    Convert following hex to binary

    9 290A

    1E DDC

    FFF ABC

    Did you notice the pattern? Decimal is closely related to BCD (very easy to convert between thetwo) and the same can be said for Hexadecimal and Binary.

    Binary to BCD Shift and Add-3 Algorithm

    1. Shift the binary number left one bit.

    2. If 8 shifts have taken place, the BCD number is in theHundreds, Tens, and Units column.

    3. If the binary value in any of the BCD columns is 5 or greater, add 3 to that value in that BCD

    column.4. Go to 1.

    CONVERT: 0Eh to BCD

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    25/31

    Procedure

    Complete the following tasks.

    1. Launch the EMU8086.

    2. Look up and research usage of ROL instruction

    3. Copy and Paste below code into EMU8086 code windows4. Single step execution with the flags windows open

    5. The code is for BCD to Binary converter

    6. Follow the single step and watch the value of the registers after each operation

    org 0100h

    BCDBIN: xor ax,ax ; clear ax by xor it w/ itselfmov dx, BCDmov ch, 4 ; counter is 4 digit

    X10: shl ax, 1 ; 10x routine by using shlmov bx, axmov cl, 2shl ax, cladd ax,bx

    ADDDIGIT: mov cl, 4 ; specify how many bits to shiftrol dx, cl ; roll bit left by "cl" bit = 4 bits

    mov bx,dxand bx, 000fh ; mask off our shifted DXadd ax,bx

    dec chjnz x10

    ret

    BCD dw 6789h

    Analysis

    Q1.Can you come up with the algorithm use for BCD to Binary converter after watching the

    program run?

    Q2.Can you write a program to convert Binary to BCD using the shift and add 3 algorithm?

    Q3.What did ROL do to our program when it got executed?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    26/31

    Fundamental of Microprocessor

    Lab 9: Arithmetic Operation (revisit)

    Procedure

    Write programs to do following arithmetic operation in EMU 8086 and execute them usingsingle step mode.

    AL = 12h

    BL = 13h

    1) AL + BL

    2) BLAL3) AL * BL

    4) AL / BL

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    27/31

    AX = 0123h

    BX = 2000hDX = 0FF3h

    1)

    AX + DX2) AXBX3) AX * DX

    4) AX / DX

    5) Negate BX6) Compare AX and DX

    Analysis

    Q1.What are the main differences between first set of operation and second set of operation?

    Q2.Did you notice what happens to the remainder in the division operation?

    Q3.What is the syntax for multiplication and division?

    Are they different from addition/subtraction? How?

    Q4.What happens to the flags when you do subtraction in the second set?

    Q5.What happens to the (all) flags when you do NEG operation?

    Q6.What happens to the (all) flags when you do CMP operation?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    28/31

    Fundamental of Microprocessor

    Lab 10: Connect to Outside World Applications

    Input and Output (I/O) in 8086 Assembly Language

    Each microprocessor provides instructions for I/O with the devices that are attached to it,in this lab we will just talk about OUT instruction.

    OUTOutput from AL or AX to port.

    First operand is a port number. If required to access port number over 255DX register should

    be used.

    Example:

    MOV AX, 0FFFh ; turn on all the light (or turn all binary to 1)

    OUT 4, AX ; output content of AX to port 4

    EMU8086 provide us with the virtual LED (output display). We can use this simple LED

    virtual output to test how to write a simple program that send output to the outside world.

    Procedure

    1.

    Open EMU80862. Copy and paste the following code into the code editor part of EMU80863. Single step execute the code and watch the register and flags

    4. Keep LED display windows where you can see how the display changes

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    29/31

    #start=led_display.exe##make_bin#name "led"

    mov ax, 1234out 199, ax

    mov ax, -5678out 199, ax

    ; loop to write; values to port up to specify; number (in this case it is 0010h):

    mov ax, 0x1:

    out 199, axinc axcmp ax, 0FFFEh

    jmp x1

    ret

    Analysis

    Q1. What do you have to change if we want to count all the way up to 255(decimal)?

    Q2. Can you think of any practical purpose for program like this in our real life applications?

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    30/31

    Fundamental of Microprocessor

    Lab 11: Connect to Outside World Applications (Continued)

    Input and Output (I/O) in 8086 Assembly Language

    Each microprocessor provides instructions for I/O with the devices that are attached to it,

    in this lab we will just talk about OUT instruction.

    OUTOutput from AL or AX to port.

    First operand is a port number. If required to access port number over 255DX register should

    be use.Example:

    MOV AX, 0FFFh ; turn on all the light (or turn all binary to 1)OUT 4, AX ; output content of AX to port 4

    This short program for emu8086 shows how to keep constant temperature using heaterand thermometer (between 60 to 80). It is assumed that air temperature is lower 60.

    Procedure

    1. Open EMU80862. Copy and paste the following code into the code editor part of EMU8086

    3.

    Execute the code (not in single step mode) and watch the running code display4. Keep thermometer display where you can see.

  • 8/11/2019 Artifact FLO1 2 ELab Learning Tools

    31/31

    #start=thermometer.exe#

    ; temperature rises fast, thus emulator should be set to run at themaximum speed.

    ; if closed, the thermometer window can be re-opened from emulator's"virtual devices" menu.

    #make_bin#name "thermo"; set data segment to code segment:

    mov ax, csmov ds, ax

    start:

    in al, 125

    cmp al, 60jl low

    cmp al, 80jle okjg high

    low:mov al, 1out 127, al ; turn heater "on".jmp ok

    high:mov al, 0out 127, al ; turn heater "off".

    ok:jmp start ; endless loop

    Analysis

    Q1.How did this program monitor the temperature?

    Q2.What port number is used to control the heater?