Sei sulla pagina 1di 3

Laboratory 4: Converting from Binary to ASCII(American Standard Communications Information Interchange)

Type in the following programme using EMU8086 and include your Name, Class, Group, Year and Date. Save this programme as file: lab_4.asm. ; ; ; ; ; TITLE NAME DATE CLASS GROUP

Purpose of Lab Introduction to a procedure for converting a binary value to the ASCII equivalent. REQUIREMENTS: You are required to type in the relevant parts of the procedure below using the EMU8086 Emulator. SPECIFICATION:
1. Open a new .EXE template in the EMU8086 emulator. 2. Copy the Lab 4 programme below into the relevant position of the 3. 4.

5.
6.

EMU8086 editor. Assemble and Emulate the programme using the Emulate option from the menubar. Run the programme using the Single Step option from the menubar. Examine the contents of the AX register. Finally, write a report and explanation of the 8086 assembly language procedure structure in an .EXE programme.

DESIGN: You are expected to try and understand the flow of the programme.

IMPLEMENTATION:

An algorithm to convert from Binary to ASCII. Using a decimal analogy: 127/10 = quotient 12, remainder 7 12/10 = quotient 1, remainder 2 1/10 = quotient 0, remainder 1 1. Divide by 10 and save the remainder on the stack as a significant BCD digit. 2. Repeat step 1 until the quotient is zero. 3. Retrieve each remainder and add a 30H to convert to ASCII before displaying or printing. Example 2 shows how the unsigned 16-bit contents of AX is converted to ASCII and displayed on the video screen as an unsigned integer. Here we divide AX by 10 and save the remainder on the stack after each division for later conversion to ASCII. The reason that data are stored on the stack is because the least significant digit is returned first by the division. The stack is used to reverse the order of the data so it can be displayed correctly from the most significant digit to the least. The result is displayed on the video screen, after all the digits have been converted by division, by removing the remainders from the stack and converting them to ASCII code. This procedure also blanks any leading zeros that occur.
EXAMPLE 2 DISPX PROC NEAR PUSH DX PUSH CX PUSH BX XOR CX,CX MOV BX,10 DISPX1: XOR DX,DX ;clear DX ;save remainder DIV BX PUSH DX ;save BX, CX and DX

;clear CX ;load 10

INC OR JNZ DISPX2:

CX AX,AX DISPX1

;count remainder ;test quotient ;if not zero ;display number ;convert to ASCII ;repeat ;restore BX, CX and DX

POP DX MOV AH,2 ADD INT LOOP POP POP POP RET DISPX ENDP DL,30H 21H DISPX2 BX CX DX

Potrebbero piacerti anche