AT&T 组装屏蔽输入

发布于 2024-12-16 11:26:07 字数 281 浏览 0 评论 0原文

我正在尝试在 AT&T Assembly 中创建一个简单的密码程序,但在屏蔽输入方面遇到问题。我想要发生的是当用户输入字符时,它们在屏幕上显示为星号'。在 intel 语法中,它相对简单:

mov ah, 08h
int 21h

mov dl,2ah
mov ah,02h
int 21h

它使用 intel 命令读取输入而不回显它,而是打印星号。 我正在尝试用 AT&T 语法解决这个问题,但遇到了一些麻烦。

任何意见将不胜感激。 提前致谢。

I'm trying to create a simple password program in AT&T Assembly but i'm having trouble with masking an input. What i want to happen is when the user enters characters, they appear on the screen as asterisk'. In intel syntax it's relatively simple:

mov ah, 08h
int 21h

mov dl,2ah
mov ah,02h
int 21h

This uses the intel command to read an input without echoing it and instead print an asterisk.
I'm trying to solve this problem in AT&T syntax and I'm having some trouble.

Any input would be greatly appreciated.
Thanks in advance.

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

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

发布评论

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

评论(1

能否归途做我良人 2024-12-23 11:26:07

如果我错了,请纠正我:

在 AT&T 汇编中,十六进制是 C 风格的: 0x30 而不是 30h。八进制也类似于 C 语言,以 0 为前缀。

根据您要操作的内存大小,您必须在操作数上使用该大小的后缀。这意味着在 32 位长内存上用 movl 而不是 mov

8 bits = b      - derived from "byte"
16 bits = w     - derived from "word"
32 bits = l     - I have no idea why 16 bits is usually a "dword"
64 bits = q     - derived from "qword", q for "quad-", so four words in size

值也以美元符号为前缀:$0x41(变量也是如此?)寄存器以百分号为前缀:%eax

因此,如果我正确地阅读了此内容,您的代码应该是:

movl $ah, $0x08
int 0x21

movl $dl, $2ah
movl $ah, $0x02
int $0x21

我不敢相信我在编写答案时错过了这一点,AT&T 语法已颠倒了具有两个输入的指令的源-目标顺序。

即 AT&T 是:

movl <source>, <dest>

而在英特尔语法中,这将是:

mov <dest>, <source>

欢迎任何更正,因为我也在学习。

Please correct me if I'm wrong:

In AT&T assembly hexadecimal is written C-style: 0x30 instead of 30h. Octals are also like in C, prefixed with a 0.

And depending on what size memory you are manipulating you have to use that size's postfix on the operand. That means movl instead of mov on 32bit long memory:

8 bits = b      - derived from "byte"
16 bits = w     - derived from "word"
32 bits = l     - I have no idea why 16 bits is usually a "dword"
64 bits = q     - derived from "qword", q for "quad-", so four words in size

Also values are prefixed with a dollar sign: $0x41 (as are variables?) and registers are prefixed with percent signs: %eax.

So if I'm reading this correctly your code should be:

movl $ah, $0x08
int 0x21

movl $dl, $2ah
movl $ah, $0x02
int $0x21

I can't believe I missed this when I wrote the answer, AT&T syntax has reversed source-destination order for instructions with two inputs.

I.e. AT&T is:

movl <source>, <dest>

while in Intel syntax this will be:

mov <dest>, <source>

Any corrections are welcome as I'm still learning as well.

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