将两个 4 位数字合并为一个 8 位数字
Merge two 4-bit numbers into an 8-bit number
所以问题是:
有2个字符。
我需要构建一个像这样构建的 8 位数字:
第一个数左4位,第二个数右4位
编辑:
如果数字将放在 al 中,位应该是这样的:
al 位 0 到 3 = 第二个字符的最低 4 位。
al 位 4 到 7 = 第一个字符的最高 4 位。
我试过将数字右移 4 位以获得左 4 位。
为了得到右边的 4 位,我试图将数字的左边 4 位变为 0。
然后我把ax的左4位加起来,左移4次,再把左4位加起来。
mov dl,[si] ; the value of the character, it is inside of a char array
shr dl,4
add al,dl
and dl,00001111b
shl ax,4 ; ax value was 0
inc si
mov dl,[si]
and dl,00001111b
add al,dl
shl ax,4
我认为这应该有效,但显然无效。
我该怎么做?
I need to build a 8-bit number that is built like this:
the left 4 bits from the first number, the right 4 bits from the second number
不知道你是否想要这样的东西:
mov ax,[si] ;al = first character, ah = second character
shl al,4 ;al bits 4 to 7 = lowest 4 bits of first character
shr ax,4 ;al bits 0 to 3 = lowest 4 bits of first character, al bits 4 to 7 = lowest 4 bits of second character
..或类似这样的东西:
mov ax,[si] ;al = first character, ah = second character
and ax,0xF00F ;al bits 0 to 3 = lowest 4 bits of first character, ah bits 4 to 7 = highest 4 bits of second character
or al,ah ;al bits 0 to 3 = lowest 4 bits of first character, al bits 4 to 7 = highest 4 bits of second character
..或类似这样的东西:
mov ax,[si] ;al = first character, ah = second character
and ax,0x0FF0 ;al bits 4 to 7 = highest 4 bits of first character, ah bits 0 to 3 = lowest 4 bits of second character
or al,ah ;al bits 0 to 3 = lowest 4 bits of second character, al bits 4 to 7 = highest 4 bits of first character
..或其他。
所以问题是:
有2个字符。
我需要构建一个像这样构建的 8 位数字:
第一个数左4位,第二个数右4位
编辑: 如果数字将放在 al 中,位应该是这样的:
al 位 0 到 3 = 第二个字符的最低 4 位。 al 位 4 到 7 = 第一个字符的最高 4 位。
我试过将数字右移 4 位以获得左 4 位。 为了得到右边的 4 位,我试图将数字的左边 4 位变为 0。 然后我把ax的左4位加起来,左移4次,再把左4位加起来。
mov dl,[si] ; the value of the character, it is inside of a char array
shr dl,4
add al,dl
and dl,00001111b
shl ax,4 ; ax value was 0
inc si
mov dl,[si]
and dl,00001111b
add al,dl
shl ax,4
我认为这应该有效,但显然无效。
我该怎么做?
I need to build a 8-bit number that is built like this: the left 4 bits from the first number, the right 4 bits from the second number
不知道你是否想要这样的东西:
mov ax,[si] ;al = first character, ah = second character
shl al,4 ;al bits 4 to 7 = lowest 4 bits of first character
shr ax,4 ;al bits 0 to 3 = lowest 4 bits of first character, al bits 4 to 7 = lowest 4 bits of second character
..或类似这样的东西:
mov ax,[si] ;al = first character, ah = second character
and ax,0xF00F ;al bits 0 to 3 = lowest 4 bits of first character, ah bits 4 to 7 = highest 4 bits of second character
or al,ah ;al bits 0 to 3 = lowest 4 bits of first character, al bits 4 to 7 = highest 4 bits of second character
..或类似这样的东西:
mov ax,[si] ;al = first character, ah = second character
and ax,0x0FF0 ;al bits 4 to 7 = highest 4 bits of first character, ah bits 0 to 3 = lowest 4 bits of second character
or al,ah ;al bits 0 to 3 = lowest 4 bits of second character, al bits 4 to 7 = highest 4 bits of first character
..或其他。