AT&T Assembly Masked Input

别来无恙 提交于 2019-12-08 09:12:59

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8182165/att-assembly-masked-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!