8085汇编:符号扩展8位到16位

时间:2015-01-14 17:21:04

标签: assembly 8085

如何签名将一组8位数字扩展为16位并以小端格式存储它们。例如,我的内存位置有以下数据。

Address = Value
0001    = 03 [counter]
0002    = 05
0003    = 43
0004    = 8C

结果:

Address = Value
0005    = 05 \ 05 => 00 05
0006    = 00 /
0007    = 43 \ 43 => 00 43
0008    = 00 /
0009    = 8C \ 8C => FF 8C
000A    = FF /

我目前停留在以下代码中:

LXI D,0005H [memory location to store little endian]
LXI H,0001H 
MOV C,M  [initialize counter]
INX H  [increment 1 and point to first data]
MOV A,M
CALL EXPAND
HLT

Expand: PUSH B
PUSH H
checkMSB: ANI 80H  [Check the MSB to determine expand number whether is 00 or FF]
JZ SKIP
..... [still on process]

SKIP: STAX D [stuck at here]
INX H
MOV A,M
DCR C
JNZ checkMSB
POP H
POP B
HLT

2 个答案:

答案 0 :(得分:0)

执行类似

的操作
LXI D,DOUT;; destination
LXI H,DIN ;; source
MOV C,M ;; load counter
INR C
LOOP:
INX H ;; inc to next number
DCR C ;; dec counter
JZ DONE
;; load and store lo 8 bit
MOV A,M
STAX D
INX D
;; shift upper bit to carry
RAL
;; A <= A - A - CY, i.e. A <= 0x00 or 0xFF depending on CY
SBB A
;; store hi 8 bit
STAX D
INX D
JMP LOOP
DONE:
JMP DONE

DIN:
03 05 43 8C
DOUT:

如果您的要求不是这些地址,您可以使用堆栈。此外,可能会采用一些旋转/移位技巧。我不喜欢语法,所以我可能在那里有一个拼写错误。

答案 1 :(得分:0)

这也是一种可能性:

   LXI  D, 0005H ;; destination
   LXI  H, 0001H ;; source
   MOV  C,M      ;; load counter
; --- only needed if counter may be 0 ---
   MOV  A, C     ;; copy C to A
   ORA  A        ;; check if A is 0
   JZ   done
; --- ---
loop:
   INX  H        ;; inc pointer to next value
   MOV  A,M        ;; read 8-bit value
   STAX  D        ;; write low word
   INX  D        ;; increment pointer
   ADI  80h     ;; this will set CF if HSb is set
   SBB  A        ;; will result in 0FFh if CF set, 0 else
   STAX  D        ;; write high word
   INX  D        ;; increment pointer
   DCR  C        ;; dec counter
   JNZ  loop
done: