Chat GPT2 assembly programming

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
User avatar
rmbrowngr
Posts: 620
Joined: Sat Jan 13, 2018 12:46 pm
Location: Dionysos, Greece
Contact:

Chat GPT2 assembly programming

Post by rmbrowngr »

I asked chat gpt2 to write a programme to draw a cicle in mode 0 for the acorn electron and this is what it replied.

Code: Select all

Here's an assembly language program for the Acorn Electron to draw a circle in Mode 0:

```
; Circle drawing program for Acorn Electron in Mode 0

.ORG &900            ; Program starts at memory address &900

; Initialize variables
CIRCLE_X = &70       ; X coordinate of circle center
CIRCLE_Y = &50       ; Y coordinate of circle center
CIRCLE_R = &20       ; Radius of circle

; Set up Mode 0
    LDA #0           ; Mode 0
    JSR &FFF4        ; Call OSWRCH to set mode

; Draw the circle
    LDX #0           ; X coordinate
    LDY #0           ; Y coordinate
LOOP:
    TXA             ; Transfer X to A
    CLC             ; Clear carry flag
    ADC #CIRCLE_X    ; Add circle X coordinate
    STA &E0         ; Store X coordinate
    TYA             ; Transfer Y to A
    ADC #CIRCLE_Y    ; Add circle Y coordinate
    STA &E1         ; Store Y coordinate
    LDA #&C1        ; PLOT command
    JSR &FFF1        ; Call OSWORD to plot pixel
    INX             ; Increment X
    CPX #CIRCLE_R    ; Compare X to radius
    BNE LOOP        ; Loop if not equal
    DEX             ; Decrement X
LOOP2:
    TXA             ; Transfer X to A
    CLC             ; Clear carry flag
    SBC #1          ; Decrement X
    TAX             ; Transfer X back
    TYA             ; Transfer Y to A
    CLC             ; Clear carry flag
    ADC #1          ; Increment Y
    TAY             ; Transfer Y back
    JSR &FFF1        ; Call OSWORD to plot pixel
    CPX #0          ; Compare X to 0
    BNE LOOP2       ; Loop if not equal
    CPY #CIRCLE_R    ; Compare Y to radius
    BNE LOOP2       ; Loop if not equal

; Program end
    RTS             ; Return from subroutine
```

This program sets the Acorn Electron to Mode 0, then uses a nested loop to draw a circle using the Bresenham circle algorithm. The circle is centered at the coordinates `(CIRCLE_X, CIRCLE_Y)` and has a radius of `CIRCLE_R`.

To use this program, you would need to assemble it and load it into the Acorn Electron's memory. You can then call the program by jumping to the start address `&900`.

Note that this is a basic example and does not include any error handling or user input. In a real application, you may want to add additional functionality and error checking.
Richard B
Acorn Electrons issue 4 and 6, MRB, Plus 1 x2, Plus 3, AP6 x2, AP5, Pegasus 400, BeebSCSI, Gotek, Raspberry Pi Co-processor, GoSDC MBE.
BBC B+ 64K (128K upgraded) with Duel OS, Raspberry Pi Co-processor and Gotek.
User avatar
Lardo Boffin
Posts: 2979
Joined: Thu Aug 06, 2015 7:47 am
Contact:

Re: Chat GPT2 assembly programming

Post by Lardo Boffin »

Does it work?
Adventure Language on GitHub
Atom, issue 5, YARRB + video noise killer
Elk
A number of econetted (is that a word?) Beebs
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA
SteveF
Posts: 1697
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: Chat GPT2 assembly programming

Post by SteveF »

Lardo Boffin wrote: Sat May 04, 2024 10:59 am Does it work?
Sadly I don't think it will. It's doing VDU 0 to select mode 0 instead of VDU 22,0 for starters.

It's an interestingly mangled attempt though. It looks like it is using the GXR &C1 "plot ellipse" operation, which won't work on a standard Electron, and it's using OSWORD to do the PLOT instead of VDU 25.

I wonder if GPT3 or 4 would make a better fist of this? (Edit: OK, a quick web search shows that chatgpt2 is not the same as GPT-2 from a few years back, e.g. I found this, I just got confused. Still, whatever it is, it didn't do a great job.)
User avatar
BeebMaster
Posts: 7416
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Chat GPT2 assembly programming

Post by BeebMaster »

SteveF wrote: Sat May 04, 2024 5:10 pm It's doing VDU 0 to select mode 0
It's not even doing that:

Code: Select all

; Set up Mode 0
    LDA #0           ; Mode 0
    JSR &FFF4        ; Call OSWRCH to set mode
It's doing OSBYTE 0, which will print "OS 1.00" !
Image
SteveF
Posts: 1697
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: Chat GPT2 assembly programming

Post by SteveF »

Ha! It got me, well spotted. I should have remembered:
Don't get suckered in by the comments - they can be terribly misleading: Debug only the code.
Edit: Anyone know who said that? My web searches turn up attributions to both G(uy?) Steele and Dave Storer.
User avatar
BigEd
Posts: 6280
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: Chat GPT2 assembly programming

Post by BigEd »

Looks most likely (to me) to be Dave Storer. Here's the Bumper Sticker Computer Science edition of the Programming Pearls column by Jon Bentley: 1985, 6 page PDF and perhaps also here as a web page. Edit: more programming quotes here on wikiquote.

Edit: that said, I can find nothing about a Dave Storer of Cedar Rapids.
SteveF
Posts: 1697
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: Chat GPT2 assembly programming

Post by SteveF »

Thanks Ed! Looking at the start of that Programming Pearls PDF, it says:
A word about credit. The name associated with a rule is usually the person who sent me the rule, even if they in fact attributed it to their Cousin Ralph (sorry, Ralph). In a few cases 1 have listed an earlier reference, together with the author’s current affiliation (to the best of my knowledge].
So if I'm reading this right, that's pretty ambiguous. It may be Dave Storer sent this quote in (perhaps attributing it to Guy Steele, even), or it may be that he said it. It wouldn't surprise me if the attribution from this article then got copied around, whether it was correct or not, but I'm just guessing.
User avatar
BigEd
Posts: 6280
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: Chat GPT2 assembly programming

Post by BigEd »

Oh good spot - I didn't read all of the thing I linked, and that's now obvious!

Where do you see a Guy Steele attribution? I looked for that first, but came up with nothing.
SteveF
Posts: 1697
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: Chat GPT2 assembly programming

Post by SteveF »

I struggled to find it again, but I think this was the main one: https://softwarequotes.com/author/g--steele

But you're right, the vast majority of attributions on the web (although it honestly feels like all the search engines are terrible these days, but that's maybe just me) do seem to be for Dave Storer.

Edit: And in a delightfully pseudo-recursive twist, this thread itself came up in some of my searches while I was trying to locate that site.
User avatar
BigEd
Posts: 6280
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: Chat GPT2 assembly programming

Post by BigEd »

Ah, thanks for the link! It doesn't feel to me especially like the kind of phrasing I'd expect from Guy Steele, but who knows (I'm not quite inclined to email him to ask...)
Post Reply

Return to “programming”