Re: A basic question on asm
From: KVP (spamtrap_at_crayne.org)
Date: 09/22/04
- Previous message: Tim Roberts : "Re: gamma correction"
- In reply to: Matt: "Re: A basic question on asm"
- Next in thread: Matt: "Re: A basic question on asm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 22 Sep 2004 06:48:22 +0000 (UTC)
"Matt" <spamtrap@crayne.org> wrote:
> "Ivan Korotkov" <spamtrap@crayne.org> wrote:
> >> The problem is more that GDB chose a horrible representation of the
> >> construct, and that fewer people are familiar w/ AT&T syntax. I like
> >> AT&T because of the explicit register notation (%), the more intuitive
> >> argument order (src,dest)
> > [snip]
> > Do you think that subl 1, %eax is more intuituve?
> Ah this discussion has been held more times than can be counted. It boils
> down to a matter of preference. My preference falls in-line with yours, but
> I recall when I first learned C I found the ordering of arguments (i.e.
> strcpy(dest, src)) to be very confusing and backward. It is only now that I
> am used to it that I want my assembler to work the same way.
At&t syntax looks better on an architecture where you could write:
subl %src1, %src2, %dst
for example:
subl %1, $1234, (%2)+
On the original architecture, it was more elegant. It doesn't have the
% prefix on the registers, but the syntax is src, dst. One interesting
thing is the use of relative labels. (1f, 1b) /btw. the platform is pdp11/
The example:
/ chown -- change owner
.globl fopen, getc, mesg
mov sp,r5
mov (r5),r4
cmp r4,$3
bge 1f
jsr r5,mesg; <chown uid f1 ...\n\0>; .even
1:
add $4,r5
mov (r5),r3
cmpb (r3),$'0
blt 1f
cmpb (r3),$'9
bgt 1f
jsr r5,cvnum; geta
br do
1:
mov $uids,r0
jsr r5,fopen; ubuf
bec 1f
jsr r5,mesg; <Can't open /etc/uids\n\0>; .even
sys exit
1:
mov r3,r2
2:
jsr r5,getc; ubuf
bcc 3f
who:
jsr r5,mesg; <Who?\n\0>; .even
sys exit
3:
cmp r0,$':
beq 3f
cmpb (r2)+,r0
beq 2b
2:
jsr r5,getc; ubuf
bcs who
cmp r0,$'\n
bne 2b
br 1b
3:
tstb (r2)
bne 2b
3:
jsr r5,getc; ubuf
cmpb r0,$':
bne 3b
jsr r5,cvnum; getc
do:
sub $2,r4
mov r1,0f+2
tst (r5)+
1:
mov (r5),0f
mov (r5)+,9f
sys stat; 9:..; statb
movb statb+8,0f+3
sys chown; 0:..; 0
bec 2f
mov 0b,r0
mov r0,0f
clr 0f+2
3:
tstb (r0)+
beq 3f
inc 0f+2
br 3b
3:
mov $1,r0
sys write; 0:..; ..
jsr r5,mesg; <?\n\0>; .even
2:
dec r4
bgt 1b
sys exit
cvnum:
clr r1
1:
jsr r5,*(r5); ubuf
bcs 1f
sub $'0,r0
cmp r0,$9.
bhi 1f
mpy $10.,r1
add r0,r1
br 1b
1:
tst (r5)+
rts r5
geta:
movb (r3)+,r0
tst (r5)+
rts r5
uids: </etc/passwd\0>
.bss
statb: .=.+36.
ubuf: .=.+518.
> >From the perspective of writing an assembler, I prefer a variant of nasm
> syntax with % prefixed to the register names, unambiguous 0-operand
> instructions (i.e. pushfw/pushfd), and single-mneumonic, unambiguous control
> transfer instructions (i.e. calln/callf, iretw/iretd, retn/retf, ...). But
> that's just me...
Most of us would like an assembler with this syntax, and I would add
structure and macro support as an extra.
Viktor
- Previous message: Tim Roberts : "Re: gamma correction"
- In reply to: Matt: "Re: A basic question on asm"
- Next in thread: Matt: "Re: A basic question on asm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|