问题
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