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 7 (Logic, Shift,...
PDF
Introduction to ibm pc assembly language
PDF
Chapter 5The proessor status and the FLAGS registers
PDF
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
PDF
Assembly Langauge Chap 1
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
PDF
Chapter 6 Flow control Instructions
chapter 7 Logic, shift and rotate instructions
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Introduction to ibm pc assembly language
Chapter 5The proessor status and the FLAGS registers
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
Assembly Langauge Chap 1
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Chapter 6 Flow control Instructions

What's hot (20)

PPTX
8086 Instruction set
PPTX
Logical, Shift, and Rotate Instruction
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
DOCX
Instruction set of 8086
PDF
Organization of the ibm personal computers
PPTX
Addressing Modes Of 8086
PDF
Representation of numbers and characters
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
PPT
Assembly Language Lecture 5
PPT
8086-instruction-set-ppt
PPTX
DMA operation
PDF
8086 instruction set (with simulator)
ODP
APB protocol v1.0
PDF
assembly language programming and organization of IBM PC" by YTHA YU
PPTX
Flow control instructions
PPT
Logic, shift and rotate instruction
PPTX
Stack and its usage in assembly language
PDF
8086 instructions
PPTX
Addressing modes of 8086
PPTX
Input output interface
8086 Instruction set
Logical, Shift, and Rotate Instruction
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Instruction set of 8086
Organization of the ibm personal computers
Addressing Modes Of 8086
Representation of numbers and characters
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Lecture 5
8086-instruction-set-ppt
DMA operation
8086 instruction set (with simulator)
APB protocol v1.0
assembly language programming and organization of IBM PC" by YTHA YU
Flow control instructions
Logic, shift and rotate instruction
Stack and its usage in assembly language
8086 instructions
Addressing modes of 8086
Input output interface
Ad

Viewers also liked (6)

PPTX
bubble sorting of an array in 8086 assembly language
PDF
8086 microprocessor lab manual
PPTX
File handling functions
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
PPT
14 file handling
 
DOCX
PROJECT REPORT_ONLINE VOTING SYSTEM
bubble sorting of an array in 8086 assembly language
8086 microprocessor lab manual
File handling functions
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
14 file handling
 
PROJECT REPORT_ONLINE VOTING SYSTEM
Ad

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

PPTX
[ASM]Lab7
PPT
Computer Organization & Assembly Language Logic Instructions
PDF
Computer Organization & Assembly Language Logic Instructions
PDF
8086 instruction set
PDF
8086 instruction set
PDF
8086 instruction set
PPTX
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
PPTX
L12_ COA_COmputer architecurte and organization
PPT
How Assembly works, and Logics made in Assembly language
PPTX
int 21 h for screen display
[ASM]Lab7
Computer Organization & Assembly Language Logic Instructions
Computer Organization & Assembly Language Logic Instructions
8086 instruction set
8086 instruction set
8086 instruction set
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
L12_ COA_COmputer architecurte and organization
How Assembly works, and Logics made in Assembly language
int 21 h for screen display

More from Bilal Amjad (13)

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)
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
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 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
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)

PDF
August 2025 Top read articles in International Journal of Database Managemen...
PPTX
Soumya Das post quantum crypot algorithm
PPTX
unit 1 computer graphics introduction types
PDF
B461227.pdf American Journal of Multidisciplinary Research and Review
PPTX
Cloud Security and Privacy-Module-2a.pptx
PDF
IMDb_Product_Teardown_product_management
PPTX
Embedded Systems Microcontrollers and Microprocessors.pptx
PDF
PhD defense presentation in field of Computer Science
PPTX
240409 Data Center Training Programs by Uptime Institute (Drafting).pptx
PDF
Thesis of the Fruit Harvesting Robot .pdf
PPTX
CC PPTS unit-I PPT Notes of Cloud Computing
PDF
Snapchat product teardown product management
PPTX
Unit I - Mechatronics.pptx presentation
PDF
Human CELLS and structure in Anatomy and human physiology
PPT
Module_1_Lecture_1_Introduction_To_Automation_In_Production_Systems2023.ppt
PPTX
22ME926Introduction to Business Intelligence and Analytics, Advanced Integrat...
PDF
M01-Manage Safety and Environmental Protection 1.pdf
PDF
Manual variador de corriente directa parker.pdf
PPTX
Electric vehicle very important for detailed information.pptx
PPT
linux chapter 1 learning operating system
August 2025 Top read articles in International Journal of Database Managemen...
Soumya Das post quantum crypot algorithm
unit 1 computer graphics introduction types
B461227.pdf American Journal of Multidisciplinary Research and Review
Cloud Security and Privacy-Module-2a.pptx
IMDb_Product_Teardown_product_management
Embedded Systems Microcontrollers and Microprocessors.pptx
PhD defense presentation in field of Computer Science
240409 Data Center Training Programs by Uptime Institute (Drafting).pptx
Thesis of the Fruit Harvesting Robot .pdf
CC PPTS unit-I PPT Notes of Cloud Computing
Snapchat product teardown product management
Unit I - Mechatronics.pptx presentation
Human CELLS and structure in Anatomy and human physiology
Module_1_Lecture_1_Introduction_To_Automation_In_Production_Systems2023.ppt
22ME926Introduction to Business Intelligence and Analytics, Advanced Integrat...
M01-Manage Safety and Environmental Protection 1.pdf
Manual variador de corriente directa parker.pdf
Electric vehicle very important for detailed information.pptx
linux chapter 1 learning operating system

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