-
Because I don't know which microcontroller this is and the specific assembly syntax it corresponds to, but the basic idea is:
Extract the three-digit number in a, the specific method: use the remainder method, that is, divide the number in a by 100 to get the coefficient on the hundred digit (that is, the bcd code of the hundred), and then save it to one of the three storage units with result as the address. Then divide the number in a by 10 to get the coefficient and remainder on the ten digits (also the BCD code for the ten digits and the single digits, respectively), and then store them in the other two units of the three storage cells with result as the address.
-
result equ 20h
org 0ljmp start
org 0100h
bintobcd:
mov r0, #result ;Destination address.
mov b, #
div ab ;Divide by 10
mov @r0, b ;In b is the remainder, which is the single digit.
inc r0 ;Modify the address.
mov b, #
xch a, b
div ab ;Divide by 10
mov @r0, b ;In b is the remainder, which is the number of tens of digits.
inc r0 ;Modify the address.
mov @r0, a ;Save hundreds.
retstart:
mov sp, #40h
mov a, #
call bintobcd
ljmp $
-
First of all, you need to convert binary numbers to decimal numbers.
There are many kinds of decimal number BCD codes, you can choose one yourself:
-
Generally speaking, the default BCD code is 8421 code, that is, a 4-digit binary number is used to represent a 1-digit decimal number with 10 bits 0-9. The weight from left to right is 8,4,2,1.
Take decimal 37 as an example, and convert:
3 = 2 + 1 = (8421 yards) 0011, 7 = 4 + 2 + 1 = (8421 yards) 0111.
So 37 translates to 8421 yards as 0011 0111.
-
In mathematics, we all know that any decimal number such as 5468 can be converted to: 5468 5 1000 4 100 6 10 8, so the algorithm for turning the BCD code into a binary number is:
abcd=a*1000+b*100+c*10+d。
This algorithm is the most conventional algorithm, which requires the use of multipliers and adders, this implementation is more resource-intensive, the following Mengyi brother will introduce an algorithm, this algorithm needs to use addition and shift to complete the function of BCD to binary numbers, so as to save logical resources as much as possible.
Shifting the binary code one bit to the left equals the unshifted binary code 2, for example, if there is a binary code 101001, converting it to decimal is equal to 41, and shifting it one bit to the left gives 1010010, and converting it to decimal is equal to 82.
That is, a 1-bit shift to the left plus 3 bits to the left of the binary code can be equivalent to a binary code multiplied by 10.
Analyze with examples: decimal number 29;
Represented by BCD code: the decimal number on the ten bit is 2 and the BCD code is represented as 0010; The decimal number 9 BCD code on the single digit is represented as 1001; So in general, the decimal number 29 is expressed in BCD code as: 00101001.
Conversion process: Shift the BCD code 0010 (the decimal number is 2 on the decimal number) to the right by 4 digits (in fact, it means that it is a single digit, or the accompanying traveler says a simple value), and then multiply it by 10 to restore the decimal weight (because this number originally represents the ten digits in the decimal number). After processing the number in the ten digits, then the number in the single digit.
Because the weight of the BCD code is the same as the weight of the first four digits of binary (2 n, n is the number of digits), it is enough to add it directly with the number on the first ten digits.
Simple point analysis: 0010 (2bcd code on ten bits) 10 1001 (9bcd code on single digits) 29 binary numbers.
c** means: define bcd to bin(val) (val) >4) *10) +val)&15)).
-
The 4-digit binary of the BCD code represents a number, and the difference with the hexadecimal system is that there are only a few numbers from 0 to 9, for example, the BCD code of 10 is 0001
23 BCD code.
-
The bitwise conversion of BCD codes can reduce the amount of computing at the expense of memory.
1 BCD**, i.e. binary-coded decimal.
2 Four bits are used to store a decimal number.
3 Most commonly used in the design of accounting systems.
The advantage is that the conversion does not need to be considered numerical value, and the speed is fast.
The disadvantage is that 4 digits could have saved 16, but only 10 can be saved here, wasting storage.
Therefore, it is necessary to weigh which method to use for specific occasions.
-
The BCD code is an encoding form that uses four bits to store a decimal digit, allowing for quick and easy conversion between binary and decimal systems. This coding technique is most commonly used in the design of accounting systems, which often require accurate calculations on long strings of numbers. Compared with the general floating-point notation, the BCD code can not only save the accuracy of the value, but also avoid the time spent by the computer in floating-point arithmetic.
For example, if you want to use 0000 1111, this binary number is expressed as 0x0f in hexadecimal system and 0x15 as 0001 0101 in compressed bcd. That is, every 4 digits can be represented by a number of 0 - 9, which is very easy to view, calculate, input and output.
Missing those abcdef). This is especially true for floating-point numbers, where you print out a binary expression of a float number on your computer and look at it to see if you can understand it. Hehe.
-
The way to adjust the binary number BCD code is to move the binary code to the left 8 times, and check whether the lower four bits LSD+3 is greater than 7 after each shift, if so, add 3, otherwise do not add, and the high 4 bits MSD are treated in the same way.
Binary 1111, i.e. 2 1111, is equal to 10 of 15. BCD 1111 is an illegal data, because the BCD code can only represent a decimal number between 0 and 9, and this string 2 1111 is still equal to 10
Because the definition of BCD code is to use a four-digit binary number to represent a decimal number between 0-9. If it is bcd 15, then it can be translated as 2 0001 0101, so that the decimal value is 21.
-
Every four digits of the BCD code represents a decimal number. For example, the binary number 01111111, its corresponding decimal number is 127, the BCD code (four digits) corresponding to 1 is 0001, the BCD code corresponding to 2 is 0010, and the BCD code corresponding to 7 is 0111Together.
The BCD code corresponding to 127 is the 000100100111
-
Binary to decimal will you turn? The general process of converting binary to BCD code is to convert it to decimal system first and then to BCD code. For example, the binary code 1100 represents the decimal 12, and the BCD code corresponding to 12 is 00010010, because it is a one-digit turn, so 12 corresponds to 2 groups of eight BCD codes, the 1 of the ten digits corresponds to 0001, and the 2 of the single digit corresponds to 0010.
Vice versa. For example, the BCD code 000101011000 represents the decimal number 158, and the binary code corresponding to 158 is 10011110. If you don't understand something, you are welcome to continue to ask questions and communicate together
-
Hexadecimal b is also 11 in decimal, which is equal to 8 plus 2 plus Soshan Yan 1, and the result is 10111100.
Introduction to the base system:
1. The base system is also the carry counting system, which is an artificially defined counting method with carry (there are counting methods without carrying, such as the original knotted rope counting method, the orthographic counting method commonly used when recording tickets, and similar tally mark counting).
2. For any kind of base x, it means that the number of the sails in the position of each silver is calculated by one digit of x. Decimal is every 10 to 1, hexadecimal is 1 to 16, binary is every 2 to 1, and so on, x base is every x round.
Carry position notation is a way of noting, so it is also known as carry notation of place value, which can represent all numerical values with limited number symbols.
3. The number of number symbols that can be used is called the base number (en:radix) or the base number, and the base number is n, which can be called the n-carry system, referred to as the n-base system. The most commonly used system is the decimal system, which is usually counted using 10 Arabic numerals from 0 to 9.
For any one number, it can be expressed in different carry systems. For example, the decimal number 57 can be expressed as 111001 in binary or 212 in pentacimal. <>
-
The bcd code of the base number is actually the conversion of binary into decimal, for example, the conversion of binary 01001000b into decimal is 72, and the corresponding bcd code of the chain is 72h; The steps of converting binary into shed block ASC code are, splitting 0100 and 1000 according to 4 bits, respectively, converting into 16 base is 4h and 8h, and both are 9h, at this time, only need to add 30h respectively after the asc code of this binary number, that is, late file 3438h, when 9h··· I haven't learned how to do the math yet, next time.
1.Binary 1000 is replaced by 16.
With the 8421 conversion method, that is, from left to right, 8*1+4*0+2*0+1*0=0x8, this is the universal conversion method for all hexadecimal to binary, bit-to-bit alignment conversion, multiply by 8421 respectively, and then add up. If the binary number. >>>More
If it's a method, I can give you a natural language description of how the decimal integer part n can be converted to binary as follows: >>>More
Do you know how to do the math?If I don't understand, I can't help it.
The above statement is wrong.
How to calculate the binary of 1100 111. >>>More
Complement10000000, how big does it mean? >>>More