SlideShare a Scribd company logo
9
Most read
11
Most read
16
Most read
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)
Microprocessor
Instructor Mam Yumna Bilal
Group Members
 Abdul Qayum
 Imran Khan
 Adnan Murtaza
 Usman Mahmood
 Ahmad Ali
 M.Shebaz Shreef
Binary input:
For binary Input, we assume a program reads In a binary number
from the keyboard, followed by a carriage return.
The number actually Is a character string of O's and l's.
As each character Is entered, we need to convert it to a bit value,
and collect the bits in a register.
Clear BX /* BX will hold binary value */
Input a character /* '0' or '1' */
WHILE character <> CR DO
Convert character to binary value
Left shift BX
Insert value into 1sb of BX
Input a character
END_WHILE
Clear BX
BX
Input character '1', convert to 1
AND AL,OFH
Left Shift BX
CF BX
Insert value into lsb
BX
Input character ‘1' , convert to 1 AND AL,OFH
Left shift BX
CF BX
Insert value into lsb
BX
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 00
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
Input character '0' convert to o AND AL,OFH
Left shift BX
CF BX
Insert value into lsb
BX = 0000 0000 0000 0110
BX contains 110b
The algorithm assumes (1) input characters are either "O", “1", or
CR, and (2) at most 16 binary digits are input.AS a new digit Is
Input, the previous bits in BX must be shifted to the left to make
room; then an OR operation can be used to insert the new bit
into BX.
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 00
XOR BX, BX ; clear BX
MOV AH, 1 ;input char function
INT 21H ;read a character
WHILE_:
CMP AL, ODH ;CR?
JE END_WHILE ;yes, done
AND AL, OFH ;no convert to binary Value
SHL BX, 1 ;make room for new value
OR BL,AL ;put value into BX
INT 21H ;read a character
JMP WHILE_ ;loop back
END_WHILE:
Algorithm for Binary Output:
FOR 16 times DO
Rotate left BX /* BX holds output value,
put msb into CF */
IF CF = 1
THEN
output ‘1’
ELSE
output ‘0’
END_IF,
END_FOR
Mov CX,16
Top:
ROL BX,1
JNC Next
Mov AH,2
Mov DL,1
JMP Ali
Next:
Mov DL,2
Mov DL,0
Ali:
Int 21H
Int Top
loop Top
Hex input consists of digits ("0" to "9") and letters ("A" to "F”)
followed by a carriage return.
For simplicity, we assume that (1) only uppercase letters are
used, and (2) the user inputs no more than four hex characters.
The process of converting characters to binary values Is more
Involved than it was for binary input.
BX must be shifted four times to make room for a hex value.
Clear BX /* BX will hold input value */
input hex character
WHILE character <> CR DO
convert character to binary value
left shift BX 4 times
insert value into lower 4 bits of BX
input a character
END_WHlLE
Clear BX
BX
Input '6', convert to 0110
Left, shift BX 4 times
CF BX
Insert value into lower 4 bits of BX
BX
Input 'A', convert to Ah = 1010
Left shift BX 4 times
CF BX
Insert value into lower 4 bits of BX
BX
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 00
0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0
Input 'B', convert to 1011
Left shift BX 4 times
CF BX
Insert value into lower 4 bits of BX
BX
BX contains 06ABh.
Here is the code:
XOR BX,BX ;clear BX
MOV CL,4 ;counter for 4 shifts
MOV AH,1 ; input character function
INT 21H ; input a character
WHILE_:
0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 00
0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1
CMP AL,ODH ;CR?
JE END WHILE ;yes, exit
;convert character to binary value
AL, 39H ;a digit?
CMP AL, 39H ;a digit?
JG LETTER. ; no, a letter
; input is a digit
AND AL,OFH ;convert digit to binary value
JMP SHIFT ;go to insert in BX
LETTER:
SUB AL, 37H ;convert letter to binary value
SHIFT:
SHL BX, CL ;make room for new value
;insert value into BX
CR BL, AL ;put vi!lue into low 4 bits
;of BX
INT 21H ; input a character
JMP WHILE_ ; loop until CR
END_WHILE:
BX contains 16 bits, which equal four hex digit values.
To output the contents of BX, we start from the left and get hold of
each digit, convert it to a hex character, and output it.
Algorithm for Hex Output:
FOR 4 times DO
Move BH to DL /* BX holds output value *I
Shift DL 4 times to the right
IF DL < 10
THEN
convert to character in '0' .. '9.
ELSE
convert to character in 'A' .. 'F‘
END_IF
output character
Rotate BX left 4 times
END FOR
BX = 4CA9h = 0100 1100 1010 1001
Move BH to DL
DL = 0100 1100
Shift DL 4 times to the right
DL = 0000 0100
convert to character and output
DL = 0011 0100 = 34h = '4'
Rotate BX left. 4 times
BX = 1100 1010 1001 0100
Move BH to DL
DL = 1100 1010
Shift DL 4 times t0 the right
DL = 0000 1100
Convert to character and output
DL = 0100 0011 = 43h =‘C’
Rotate BX left 4 times
BX = 1010 1001 0100 1100
Move BH to DL
DL = 1010 1001
Shift DL 4 times to the right
DL = 0000 1010
Convert, to character and output
DL = 0100 0010 = 42h ='B'
Rotate BX left"4 times
BX = 1001 0100 1100 1010
Move BH to DL
DL = 1001 0100
Shift DL 4 times to the right
DL = 0000 1001
Convert to character and output
DL = 0011 1001 =39h = '9'
Rotate BX 4 times to the left
BX = 0100 1100 1010 1001 = original contents

More Related Content

PDF
chapter 7 Logic, shift and rotate instructions
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PDF
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
PDF
Representation of numbers and characters
PDF
assembly language programming and organization of IBM PC" by YTHA YU
PDF
Introduction to ibm pc assembly language
PDF
Assembly Langauge Chap 1
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
chapter 7 Logic, shift and rotate instructions
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
Representation of numbers and characters
assembly language programming and organization of IBM PC" by YTHA YU
Introduction to ibm pc assembly language
Assembly Langauge Chap 1
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...

What's hot (20)

PDF
Organization of the ibm personal computers
PPTX
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
PPTX
Instruction sets of 8086
PDF
Assembly language (coal)
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
PDF
Chapter 6 Flow control Instructions
PPT
Jumps in Assembly Language.
PPTX
instructions of 8085 Microprocessor
PPTX
Assembly 8086
PPTX
Stack and its usage in assembly language
PDF
Unit 3 – assembly language programming
PPT
Assignment on alp
PDF
Library management system
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
PPTX
stack in assembally language
PDF
Chapter 5The proessor status and the FLAGS registers
PDF
COCOMO Model By Dr. B. J. Mohite
PPTX
Flag Registers (Assembly Language)
PPTX
PL/SQL - CURSORS
Organization of the ibm personal computers
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
Instruction sets of 8086
Assembly language (coal)
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Chapter 6 Flow control Instructions
Jumps in Assembly Language.
instructions of 8085 Microprocessor
Assembly 8086
Stack and its usage in assembly language
Unit 3 – assembly language programming
Assignment on alp
Library management system
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
stack in assembally language
Chapter 5The proessor status and the FLAGS registers
COCOMO Model By Dr. B. J. Mohite
Flag Registers (Assembly Language)
PL/SQL - CURSORS
Ad

Similar to Binary and hex input/output (in 8086 assembuly langyage) (20)

PPTX
Code Conversion in 8085 Microprocessor
RTF
Microprocessor File
PDF
Taller practico emu8086_galarraga
PPTX
Module 2 (1).pptx
PDF
MIC PROJECT.pdf
PDF
PDF
Coal 17 - arithematic operation in Assembly Programming
PPTX
Mod-2.pptx
PDF
Taller Ensambladores
PPTX
6_2018_11_23!09_24_56_PM (1).pptx
PPT
chapt5 and 06assemblylanguagecodesandmachinelanguage.ppt
PPTX
L12_ COA_COmputer architecurte and organization
DOCX
ARM lab programs
PDF
Assembly Complete 8086 Instruction Set
PPT
Binary numbers
PPTX
[ASM]Lab7
PDF
Lenguaje ensamblador EMU8086
PPT
Computer archi&mp
PPTX
Instruction 4.pptx
Code Conversion in 8085 Microprocessor
Microprocessor File
Taller practico emu8086_galarraga
Module 2 (1).pptx
MIC PROJECT.pdf
Coal 17 - arithematic operation in Assembly Programming
Mod-2.pptx
Taller Ensambladores
6_2018_11_23!09_24_56_PM (1).pptx
chapt5 and 06assemblylanguagecodesandmachinelanguage.ppt
L12_ COA_COmputer architecurte and organization
ARM lab programs
Assembly Complete 8086 Instruction Set
Binary numbers
[ASM]Lab7
Lenguaje ensamblador EMU8086
Computer archi&mp
Instruction 4.pptx
Ad

More from Bilal Amjad (14)

PDF
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
PDF
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
PDF
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
PDF
Big Data in Smart Grid
PPTX
Flexibility of Power System (Sources of flexibility & flexibility markets)
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
PPTX
bubble sorting of an array in 8086 assembly language
PPTX
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
PPTX
Limit of complex number
PPTX
simple combinational lock
PPTX
4-bit camparator
PPTX
Orthogonal trajectories
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Big Data in Smart Grid
Flexibility of Power System (Sources of flexibility & flexibility markets)
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
bubble sorting of an array in 8086 assembly language
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
Limit of complex number
simple combinational lock
4-bit camparator
Orthogonal trajectories

Recently uploaded (20)

DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
UNIT 4 Total Quality Management .pptx
PDF
PPT on Performance Review to get promotions
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Digital Logic Computer Design lecture notes
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
composite construction of structures.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Well-logging-methods_new................
PPT
Project quality management in manufacturing
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Welding lecture in detail for understanding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
UNIT 4 Total Quality Management .pptx
PPT on Performance Review to get promotions
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Digital Logic Computer Design lecture notes
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Mechanical Engineering MATERIALS Selection
composite construction of structures.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
R24 SURVEYING LAB MANUAL for civil enggi
Well-logging-methods_new................
Project quality management in manufacturing
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Welding lecture in detail for understanding

Binary and hex input/output (in 8086 assembuly langyage)

  • 4. Group Members  Abdul Qayum  Imran Khan  Adnan Murtaza  Usman Mahmood  Ahmad Ali  M.Shebaz Shreef
  • 5. Binary input: For binary Input, we assume a program reads In a binary number from the keyboard, followed by a carriage return. The number actually Is a character string of O's and l's. As each character Is entered, we need to convert it to a bit value, and collect the bits in a register.
  • 6. Clear BX /* BX will hold binary value */ Input a character /* '0' or '1' */ WHILE character <> CR DO Convert character to binary value Left shift BX Insert value into 1sb of BX Input a character END_WHILE
  • 7. Clear BX BX Input character '1', convert to 1 AND AL,OFH Left Shift BX CF BX Insert value into lsb BX Input character ‘1' , convert to 1 AND AL,OFH Left shift BX CF BX Insert value into lsb BX 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
  • 8. Input character '0' convert to o AND AL,OFH Left shift BX CF BX Insert value into lsb BX = 0000 0000 0000 0110 BX contains 110b The algorithm assumes (1) input characters are either "O", “1", or CR, and (2) at most 16 binary digits are input.AS a new digit Is Input, the previous bits in BX must be shifted to the left to make room; then an OR operation can be used to insert the new bit into BX. 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 00
  • 9. XOR BX, BX ; clear BX MOV AH, 1 ;input char function INT 21H ;read a character WHILE_: CMP AL, ODH ;CR? JE END_WHILE ;yes, done AND AL, OFH ;no convert to binary Value SHL BX, 1 ;make room for new value OR BL,AL ;put value into BX INT 21H ;read a character JMP WHILE_ ;loop back END_WHILE:
  • 10. Algorithm for Binary Output: FOR 16 times DO Rotate left BX /* BX holds output value, put msb into CF */ IF CF = 1 THEN output ‘1’ ELSE output ‘0’ END_IF, END_FOR
  • 11. Mov CX,16 Top: ROL BX,1 JNC Next Mov AH,2 Mov DL,1 JMP Ali Next: Mov DL,2 Mov DL,0 Ali: Int 21H Int Top loop Top
  • 12. Hex input consists of digits ("0" to "9") and letters ("A" to "F”) followed by a carriage return. For simplicity, we assume that (1) only uppercase letters are used, and (2) the user inputs no more than four hex characters. The process of converting characters to binary values Is more Involved than it was for binary input. BX must be shifted four times to make room for a hex value.
  • 13. Clear BX /* BX will hold input value */ input hex character WHILE character <> CR DO convert character to binary value left shift BX 4 times insert value into lower 4 bits of BX input a character END_WHlLE
  • 14. Clear BX BX Input '6', convert to 0110 Left, shift BX 4 times CF BX Insert value into lower 4 bits of BX BX Input 'A', convert to Ah = 1010 Left shift BX 4 times CF BX Insert value into lower 4 bits of BX BX 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 00 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0
  • 15. Input 'B', convert to 1011 Left shift BX 4 times CF BX Insert value into lower 4 bits of BX BX BX contains 06ABh. Here is the code: XOR BX,BX ;clear BX MOV CL,4 ;counter for 4 shifts MOV AH,1 ; input character function INT 21H ; input a character WHILE_: 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 00 0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1
  • 16. CMP AL,ODH ;CR? JE END WHILE ;yes, exit ;convert character to binary value AL, 39H ;a digit? CMP AL, 39H ;a digit? JG LETTER. ; no, a letter ; input is a digit AND AL,OFH ;convert digit to binary value JMP SHIFT ;go to insert in BX LETTER: SUB AL, 37H ;convert letter to binary value SHIFT: SHL BX, CL ;make room for new value
  • 17. ;insert value into BX CR BL, AL ;put vi!lue into low 4 bits ;of BX INT 21H ; input a character JMP WHILE_ ; loop until CR END_WHILE:
  • 18. BX contains 16 bits, which equal four hex digit values. To output the contents of BX, we start from the left and get hold of each digit, convert it to a hex character, and output it. Algorithm for Hex Output: FOR 4 times DO Move BH to DL /* BX holds output value *I Shift DL 4 times to the right IF DL < 10 THEN convert to character in '0' .. '9. ELSE convert to character in 'A' .. 'F‘ END_IF output character Rotate BX left 4 times END FOR
  • 19. BX = 4CA9h = 0100 1100 1010 1001 Move BH to DL DL = 0100 1100 Shift DL 4 times to the right DL = 0000 0100 convert to character and output DL = 0011 0100 = 34h = '4' Rotate BX left. 4 times BX = 1100 1010 1001 0100 Move BH to DL DL = 1100 1010 Shift DL 4 times t0 the right DL = 0000 1100
  • 20. Convert to character and output DL = 0100 0011 = 43h =‘C’ Rotate BX left 4 times BX = 1010 1001 0100 1100 Move BH to DL DL = 1010 1001 Shift DL 4 times to the right DL = 0000 1010 Convert, to character and output DL = 0100 0010 = 42h ='B' Rotate BX left"4 times BX = 1001 0100 1100 1010 Move BH to DL DL = 1001 0100 Shift DL 4 times to the right DL = 0000 1001 Convert to character and output DL = 0011 1001 =39h = '9' Rotate BX 4 times to the left BX = 0100 1100 1010 1001 = original contents