簡體   English   中英

8085組件:符號擴展8位到16位

[英]8085 assembly: sign extend 8-bit to 16-bit

如何將一組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

做類似的事情

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:

如果您的要求不是這些地址,那么可以利用堆棧。 同樣,可能會采用一些旋轉/變速技巧。 我不喜歡這種語法,所以我可能在某處有錯字。

這也有可能:

   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:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM