Intel 8085 汇编中的位移操作有何作用?

发布于 2024-12-09 12:58:49 字数 1322 浏览 9 评论 0原文

我试图向自己解释以下 8085 汇编代码

我有这段代码,要求输入两个数字(来自 IDE 中的虚拟键盘)并将它们显示在 LED 7 和 8 上:

.ORG 0000

CALL DATA
MOV C,A
CALL PRNT

CALL DATA
MOV E,A
CALL PRNT

MVI D,00H
MOV L,E
MVI H,00H

MOV A,C
DCR A
JUMP:
DAD D
DCR A
JNZ JUMP

MOV A,L
DAA
JMP IMPR

RET

DATA:
MVI A,00000000B
OUT 00H
IN 00H
RLC
RLC
RLC
RLC
ANI F0H
MOV B,A
MVI A,00000000B
OUT 00H
IN 00H
ANI 0FH
ORA B
RET

IMPR:
MOV B,A

ANI F0H
RLC
RLC
RLC
RLC
CALL NUMZ
OUT 06H
MOV A,B
ANI 0FH
CALL NUMZ
OUT 07H
RET

NUMZ:
CPI 00H
JNZ ONE
MVI A,01110111B
JMP EXIT

ONE:
CPI 01H
JNZ TWO
MVI A,01000100B
JMP EXIT

TWO:
CPI 02H
JNZ THREE
MVI A,00111110B
JMP EXIT

THREE:
CPI 03H
JNZ FOUR
MVI A,01101110B
JMP EXIT

FOUR:
CPI 04H
JNZ FIVE
MVI A,01001101B
JMP EXIT

FIVE:
CPI 05H
JNZ SIX
MVI A,01101011B
JMP EXIT

SIX:
CPI 06H
JNZ SEVEN
MVI A,01111011B
JMP EXIT

SEVEN:
CPI 07H
JNZ EIGHT
MVI A,01000110B
JMP EXIT

EIGHT:
CPI 08H
JNZ NINE
MVI A,01111111B
JMP EXIT

NINE:
CPI 09H
JNZ SAL
MVI A,01001111B
JMP EXIT

EXIT:
RET

我不包括 PRNT 因为这对我的问题并不重要。

我理解 .ORG 0000 这是程序的开始 - 它就像 Pascal 中的 BEGIN

CALL DATA 是一个子例程,它用二进制零填充累加器并在端口 0(十六进制的 00H)中显示它们(?),然后它(从虚拟键盘)获取一个数字,然后 它在位移操作中向左旋转。

我的问题是为什么?这样做有什么意义呢?有什么好处?我在维基百科上读过它,但我仍然不明白。这段代码中它的作用是什么以及为什么需要它?

I am trying to explain to myself the following 8085 assembly code

I have this code that asks for two numbers (from a virtual keyboard within the IDE) and displays them on LEDs 7 and 8:

.ORG 0000

CALL DATA
MOV C,A
CALL PRNT

CALL DATA
MOV E,A
CALL PRNT

MVI D,00H
MOV L,E
MVI H,00H

MOV A,C
DCR A
JUMP:
DAD D
DCR A
JNZ JUMP

MOV A,L
DAA
JMP IMPR

RET

DATA:
MVI A,00000000B
OUT 00H
IN 00H
RLC
RLC
RLC
RLC
ANI F0H
MOV B,A
MVI A,00000000B
OUT 00H
IN 00H
ANI 0FH
ORA B
RET

IMPR:
MOV B,A

ANI F0H
RLC
RLC
RLC
RLC
CALL NUMZ
OUT 06H
MOV A,B
ANI 0FH
CALL NUMZ
OUT 07H
RET

NUMZ:
CPI 00H
JNZ ONE
MVI A,01110111B
JMP EXIT

ONE:
CPI 01H
JNZ TWO
MVI A,01000100B
JMP EXIT

TWO:
CPI 02H
JNZ THREE
MVI A,00111110B
JMP EXIT

THREE:
CPI 03H
JNZ FOUR
MVI A,01101110B
JMP EXIT

FOUR:
CPI 04H
JNZ FIVE
MVI A,01001101B
JMP EXIT

FIVE:
CPI 05H
JNZ SIX
MVI A,01101011B
JMP EXIT

SIX:
CPI 06H
JNZ SEVEN
MVI A,01111011B
JMP EXIT

SEVEN:
CPI 07H
JNZ EIGHT
MVI A,01000110B
JMP EXIT

EIGHT:
CPI 08H
JNZ NINE
MVI A,01111111B
JMP EXIT

NINE:
CPI 09H
JNZ SAL
MVI A,01001111B
JMP EXIT

EXIT:
RET

I'm not including PRNT because it's not important for my question.

I understand .ORG 0000 which is the start of the program - it's like BEGIN in Pascal.

CALL DATA is a subroutine which fills the Accumulator with binary zeros and shows them (?) in port 0 (00H in hex), then it gets (from the virtual keyboard) a number and then it's rotated left in a bit shift operation.

My question is why ? What's the point in doing so ? What's the benefit ? I have read about it in Wikipedia but I still don't get it. What does it do in this code and why is it needed ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不在是我 2024-12-16 12:58:49

DATA 子例程加载两个 ASCII 十进制字符并将它们形成两位数字 BCD 值。它将第一个字符左移 4 位,仅保留 LS 4 位,然后将第二个字符的 LS 4 位放入结果的 LS 4 位中。

在 C 中,这大致相当于:

char c = getchar();             // get first ASCII decimal character
char result = (c << 4) & 0xf0;  // shift into MS nybble of result and mask
c = getchar();                  // get second ASCII decimal characters
result = result | (c & 0x0f);   // mask and inset into LS nybble of result
return result;

请注意,屏蔽 ASCII 十进制字符中除 LS nybble 之外的所有字符会得到其十进制等效值,例如 ASCII '4' = 0x34 => 0x04。


为了帮助清楚地说明这一点,我绘制了一个图表,逐步显示了当用户输入数字“69”(即 ASCII '6' 后跟 ASCII '9')时发生的情况,因为这两个字符被屏蔽并组合为给出数字 69 的 BCD 表示:

在此处输入图像描述

The DATA subroutine is loading two ASCII decimal characters and forming them into a two digit BCD value. It shifts the first character left by 4 bits, keeping only the LS 4 bits and then puts the LS 4 bits of the second character into the LS 4 bits of the result.

In C this would be roughly equivalent to:

char c = getchar();             // get first ASCII decimal character
char result = (c << 4) & 0xf0;  // shift into MS nybble of result and mask
c = getchar();                  // get second ASCII decimal characters
result = result | (c & 0x0f);   // mask and inset into LS nybble of result
return result;

Note that masking all but the LS nybble of an ASCII decimal character gives you its decimal equivalent, e.g. ASCII '4' = 0x34 => 0x04.


To help make this clear I have drawn a diagram which shows step-by-step what happens when the user enters the number "69", i.e. ASCII '6' followed by ASCII '9', as the two characters are masked and combined to give a BCD representation of the number 69:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文