From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18318 invoked from network); 28 Jun 2021 03:29:13 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 28 Jun 2021 03:29:13 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 550F29CB4A; Mon, 28 Jun 2021 13:29:10 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id DB8699CA5F; Mon, 28 Jun 2021 13:28:11 +1000 (AEST) Received: by minnie.tuhs.org (Postfix, from userid 112) id E710D9CA5F; Mon, 28 Jun 2021 13:28:09 +1000 (AEST) Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by minnie.tuhs.org (Postfix) with ESMTPS id BFD5D9CA3B for ; Mon, 28 Jun 2021 13:28:05 +1000 (AEST) Received: by mail-pj1-f46.google.com with SMTP id bb10-20020a17090b008ab029016eef083425so11882423pjb.5 for ; Sun, 27 Jun 2021 20:28:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=0gljlY3Gs7nUALixd4HUW0DftlhVdqFYQFHgp9He4zo=; b=c/JS7pdOFvi5o5dE4y+bAAUGyJR/4UvSUT3sTiZmmW10Yplh1Mupthx9J9Y8efcwWJ glMP8xYyY5DAFIUgIMaLi5MfA3EoCOoaH/7POtJPVY00EN23ayJVRirJxR4ogYwNSw/a c5Zd86GdhgCdnmpvxVC0jOikeKiORT84yFZwA61ILszvhleh9arkv6cAjDuakm1NW6G6 PGtZhImsbyHFHNK2DpCr4vXutjWuhzzK1P03XOHJ2wH7GncuUUpkh9R20aKyqkmtedgW 7MHxE6VyT1lr+zvQilKhCqv+Ns4Lyv9WH79MzgYo27TUkkgHxe5GkJ8eKHC7ei3KtxZg 2rJg== X-Gm-Message-State: AOAM531hUHEJKKJJ1DcrKUgETRx2F/n4xuB6IJh0bsPBxaeOIBTAQ6kN CKmSq9eucHkLhbuQSWTXV6J3ULaDjUDPh4DOUX6SQxlUxfsD0w== X-Google-Smtp-Source: ABdhPJylr6Kcf6ZdeLdy23K3SVe/reWmRzM51KydgdlZTBWb8WTDnaYuFeqBCj4ZNy9POqvYmhIOLRLDPosYvc6ITdU= X-Received: by 2002:a17:90b:1e0d:: with SMTP id pg13mr15744407pjb.56.1624850884747; Sun, 27 Jun 2021 20:28:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Paul Riley Date: Mon, 28 Jun 2021 13:27:51 +1000 Message-ID: To: tuhs Content-Type: multipart/alternative; boundary="000000000000cc662b05c5cb135a" Subject: Re: [TUHS] Using printf from Assembly Language in V6, and db. X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" --000000000000cc662b05c5cb135a Content-Type: text/plain; charset="UTF-8" Or perhaps... In my example, the substitutional arguments for printf are pushed onto the > stack in reverse order, then the address of the string, and then printf is > called. After this, 6 is added to the stack pointer. I assume that the > printf routine pops the address of the string off the stack, but leaves the > other values on the stack, hence the need to add 2x3=6 to the stack after > calling printf in my example. > ... just adding 2 for every decrement that was done on sp... Paul *Paul Riley* Mo: +61 (0)411 781 394 Email: paul@rileyriot.com On Mon, 28 Jun 2021 at 12:34, Paul Riley wrote: > Hi, > > I want to use printf from an assembly language program, in V6. It seems > that the Unix Programmer's Manual doesn't show how to use it from assembly, > so I wrote a short C program and captured the assembler output, for some > clues. Listings below. > > In my example, the substitutional arguments for printf are pushed onto the > stack in reverse order, then the address of the string, and then printf is > called. After this, 6 is added to the stack pointer. I assume that the > printf routine pops the address of the string off the stack, but leaves the > other values on the stack, hence the need to add 2x3=6 to the stack after > calling printf in my example. > > What troubles me is that the stack pointer is not decremented before the > first mov, in the example below. Is this some C convention? I would assume > that the first push in my example would overwrite the top of the stack. > Perhaps I'm not used to PDP-11 stack conventions. > > I understand db only works on files like a.out or core dumps. If I wanted > to break the assembly language program to examine values, how can I force a > termination and core dump elegantly, so I can examine some register values? > > Paul > > > *Paul Riley* > > Email: paul@rileyriot.com > > int a, b, c; > int main(){ > printf("printf: start\n"); > a = 1; > b = 2; > c = 3; > printf("A = %d, B = %d, C = %d", a, b, c); > printf("printf: end\n"); > > } > > .comm _a,2 > .comm _b,2 > .comm _c,2 > .globl _main > .text > _main: > ~~main: > jsr r5,csv > jbr L1 > L2:mov $L4,(sp) > jsr pc,*$_printf > mov $1,_a > mov $2,_b > mov $3,_c > mov _c,(sp) > mov _b,-(sp) > mov _a,-(sp) > mov $L5,-(sp) > jsr pc,*$_printf > add $6,sp > mov $L6,(sp) > jsr pc,*$_printf > L3:jmp cret > L1:jbr L2 > .globl > .data > L4:.byte 160,162,151,156,164,146,72,40,163,164,141,162,164,12,0 > L5:.byte > 101,40,75,40,45,144,54,40,102,40,75,40,45,144,54,40,103,40,75,40,45,144,0 > L6:.byte 160,162,151,156,164,146,72,40,145,156,144,12,0 > # > > --000000000000cc662b05c5cb135a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Or perhaps...<= /div>

In my example, the substitutional arguments fo= r printf are pushed onto the stack in reverse order, then the address of th= e string, and then printf is called. After this, 6 is added to the stack po= inter. I assume that the printf routine pops the address of the string off = the stack, but leaves the other values on the stack, hence the need to add = 2x3=3D6 to the stack after calling printf in my example.

... just adding 2 for every decrement= that was done on sp...

Paul

<= div>Paul Riley

=
Mo: +61 (0)411 781 394

=


On Mon, 28 Jun 2021 at = 12:34, Paul Riley <paul@rileyriot.= com> wrote:
Hi,

I want to use printf = from an assembly language=C2=A0program,=C2=A0in V6. It seems that the Unix = Programmer's Manual doesn't show how to use it from assembly, so I = wrote a short C program and captured the assembler output, for some clues. = Listings below.

In my example, the substitutional = arguments for printf are pushed onto the stack in reverse order, then the a= ddress of the string, and then printf is called. After this, 6 is added to = the stack pointer. I assume that the printf routine pops the address of the= string off the stack, but leaves the other values on the stack, hence the = need to add 2x3=3D6 to the stack after calling printf in my example.
<= div>
What troubles me is that the stack pointer is not decrem= ented before the first mov, in the example below. Is this some C convention= ? I would assume that the first push in my example would overwrite the top = of the stack. Perhaps I'm not used to PDP-11 stack conventions.

I understand db only works on files like a.out or core du= mps. If I wanted to break the assembly language program to examine values, = how can I force a termination and core dump elegantly, so I can examine som= e register values?

Paul


Paul R= iley


int a, b, c;
int main(){
=C2=A0 printf("printf: s= tart\n");
=C2=A0 a =3D 1;
=C2=A0 b =3D 2;
=C2=A0 c =3D 3;
= =C2=A0 printf("A =3D %d, B =3D %d, C =3D %d", a, b, c);
=C2=A0= printf("printf: end\n");

}

.comm =C2=A0 _a,2
.c= omm =C2=A0 _b,2
.comm =C2=A0 _c,2
.globl =C2=A0_main
.text
_mai= n:
~~main:
jsr =C2=A0 =C2=A0 r5,csv
jbr =C2=A0 =C2=A0 L1
L2:mov= =C2=A0$L4,(sp)
jsr =C2=A0 =C2=A0 pc,*$_printf
mov =C2=A0 =C2=A0 $1,_= a
mov =C2=A0 =C2=A0 $2,_b
mov =C2=A0 =C2=A0 $3,_c
mov =C2=A0 =C2= =A0 _c,(sp)
mov =C2=A0 =C2=A0 _b,-(sp)
mov =C2=A0 =C2=A0 _a,-(sp)
= mov =C2=A0 =C2=A0 $L5,-(sp)
jsr =C2=A0 =C2=A0 pc,*$_printf
add =C2=A0= =C2=A0 $6,sp
mov =C2=A0 =C2=A0 $L6,(sp)
jsr =C2=A0 =C2=A0 pc,*$_prin= tf
L3:jmp =C2=A0cret
L1:jbr =C2=A0L2
.globl
.data
L4:.byte 1= 60,162,151,156,164,146,72,40,163,164,141,162,164,12,0
L5:.byte 101,40,75= ,40,45,144,54,40,102,40,75,40,45,144,54,40,103,40,75,40,45,144,0
L6:.byt= e 160,162,151,156,164,146,72,40,145,156,144,12,0
#

<= /div>
--000000000000cc662b05c5cb135a--