1 / 13

Binary & hex I/O

Binary & hex I/O. Binary input :. read in a binary number from keyboard, followed by a carriage return. character strings of 1’s & 0’ we need to convert each character to a bit value& collects the bits in a register. Algorithm. Clear BX ….. To hold the binary value

orde
Télécharger la présentation

Binary & hex I/O

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Binary & hex I/O

  2. Binary input : read in a binary number from keyboard, followed by a carriage return. character strings of 1’s & 0’ we need to convert each character to a bit value& collects the bits in a register

  3. Algorithm • Clear BX….. To hold the binary value • Input a character …….. ‘1’ or ‘0’ • WHILE character <> CR then Convert character to binary value Left shift BX Insert value into LSB of BX Input a character END_WHILE

  4. The algorithm assumes • Input characters are either “0”,”1”or CR • At most 16 bit are input • BX is shifted left to make room and the OR operation is used to insert the new bit into BX

  5. Code XOR BX,BX ; clear BX MOV AH,1 ; input character function INT 21H ;read a character WHILE_: CMP AL,0DH ; CR? JE END_WHILE ; yes , done AND AL,0FH ; no, convert to binary value SHL BX,1 ;make room for new value OR BL,AL ;put value in BX INT 21H ;read a character JMP WHILE_ ;loop back END_WHILE :

  6. Binary output: Outputting contents of BX in binary … Shift Operation

  7. Algorithm FOR 16 times DO Rotate left BX /* BX … output CF… MSB */ IF CF = 1 THEN output ‘1’ ELSE output ‘0’ END_IF END_FOR

  8. Binary output MOV AH, 2 MOV CX, 16 TOP: ROL BL,1 JC ONE JNC ZERO ONE: MOV DL,'1‘ ; or ( 31h) JMP DISPLAY ZERO: MOV DL,'0‘ ; or (30h ) DISPLAY: INT 21H LOOP TOP

  9. Hex Input Digits “0” to “9” & letters “A” to “F” Followed by a carriage return

  10. Assume • Only upper case letters are used. • The user inputs no more than 4 hex characters. • BX must be shifted 4 times to make room for a hex value.

  11. Algorithm for hex input • Clear BX • Input a 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_WHILE

  12. Code XOR BX,BX; clear BX MOV CL,4 MOV AH,1; input character function INT 21H;read a character WHILE_: CMP AL,0DH; CR? JE END_WHILE; yes , done ; convert character to binary digit CMP AL,39H ; a digit ? JG LETTER ; no, a letter ; input is a digit AND AL,0FH ; convert digit to binary value JMP SHIFT ; go to insert in BX

  13. Code LETTER: SUB AL, 37H ; convert letter to binary value SHIFT: SHL BX,CL ;make room for new value ; insert value into BX OR BL,AL ; put value into low 4 bits of BX INT 21H ; input a character JMP WHILE_ ; loop until CR END_WHILE:

More Related