Compilation of one-day learning (13)--16 binary display binary

Source: Internet
Author: User

This problem algorithm describes:

hexadecimal conversion to binary is the expansion of each bit:

such as 1234H expansion: 0001 0010 0011 0100

1.bx:0000 0000 0000 0000

2. Enter a legal number to convert to 0000b~1001b or to: 1010b~1111b

3. Merge with BX

4.BX shift left four bit

; receives a four-bit 16 binary number from the keyboard and displays its equivalent binary number on the terminal

DATAS SEGMENT

STR DB 0dh,0ah, ' $ '

DATAS ENDS

CODES SEGMENT

MAIN PROC Far

Assume Cs:codes, Ds:datas

START:

PUSH DS

SUB Ax, Ax

PUSH AX

MOV AX, DATAS

MOV DS, AX

;---------------------------------------------------------

MOV ch,4; hex number of four digits

MOV cl,4; shift times

MOV bx,0; store 16-bit binary

INPUT:

SHL BX, CL; move left four bits

MOV ah,01h; Enter the number of 0~9,a~f,a~f

INT 21H

CMP AL, ' 0 '

JB INPUT

CMP AL, ' F '

JA INPUT

CMP AL, ' 9 '

Jbe NUM; The number entered is 0~9

CMP AL, ' @ '

Jbe INPUT

CMP AL, ' F '

Jbe Convert1; The number of inputs is a~f

CMP AL, ' a '

JB INPUT

CMP AL, ' F '

Jbe Convert2; The number of inputs is a~f

Num:

and al,0fh; 0000b~1001b

JMP BINARY

Convert1:

and AL,0FH

ADD AL, 9

JMP BINARY

Convert2:

SUB al,20h; lowercase to uppercase in action with

and al,0fh; Convert to: 1010b~1111b

ADD AL, 9

JMP BINARY

BINARY:

or BL, AL; combine the number of keyboard inputs

DEC CH

JNZ INPUT

DISPN:

MOV CX, 16; Converts a 16-bit binary number one bit to ASCII code display

LEA Dx,str

MOV ah,09h

INT 21H

DISP:

MOV DL, 0

ROL BX, 1; Note these two instructions

RCL DL, 1

OR DL, 30H

MOV AH, 2;

INT 21H

LOOP DISP

Ret

MAIN ENDP

CODES ENDS

END START

Summary:

1. A new idea: The shift operation, the BX16 bits hold 4 hexadecimal 0000 respectively

2.AND al,0fh; Convert to: 1010b~1111b or 0000b~1001b or

hexadecimal digits and operations into the corresponding binary

3.OR

4. ROL BX, 1; cyclic left shift

RCL DL, 1; with carry loop left shift

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.