How do the hello world test work?

11 posts / 0 new
Last post
Marvan0305's picture
Online
Last seen: 1 hour 35 min ago
Joined: Sep 19 2022 - 15:54
Posts: 13
How do the hello world test work?

Hi how do the code for the hello world test work?

280:A2 C BD 8B 2 20 EF FF CA D0 F7 60 8D C4 CC D2 CF D7 A0 CF CC CC C5 C8

280.297

280

R

and what is the differences on the addresses?

Online
Last seen: 45 min 10 sec ago
Joined: Jun 29 2018 - 16:55
Posts: 223
The 1st line enters the

The 1st line enters the actual machine code

The 2nd line (280.297) repeats back that memory to screen

280R executes code starting at that location (can be one line, I usually do it that way).

 

It's my understanding that $0280 is right after the keyboard buffer, and as such it's very frequently the location which people start loading user programs into memory.

Marvan0305's picture
Online
Last seen: 1 hour 35 min ago
Joined: Sep 19 2022 - 15:54
Posts: 13
thanks

thank you but what do the numbers and letters mean in the 1st line?

Online
Last seen: 45 min 10 sec ago
Joined: Jun 29 2018 - 16:55
Posts: 223
Marvan0305 wrote:thank you
Marvan0305 wrote:

thank you but what do the numbers and letters mean in the 1st line?

Well, it is assembled machine code, but there are 6502 disassemblers easily availble:

 

https://www.masswerk.at/6502/disassembler.html

 

Here you can get the disassembled code but it probably won't mean much to you without the comments, which is why source code well commented is much easier to work with than disassembled code. 

 

If you want to start researching the insructions, you can:

 

https://sites.google.com/site/6502asembly/6502-instruction-set

 

Marvan0305's picture
Online
Last seen: 1 hour 35 min ago
Joined: Sep 19 2022 - 15:54
Posts: 13
I got this. but i don't know 
I got this. but i don't know  what the 1 and 0's are
Offline
Last seen: 8 hours 12 min ago
Joined: Nov 29 2020 - 19:48
Posts: 88
A more full assembly lang

A more full assembly lang listing might look more like

        ORG $280                               ; start the program at $280CharOut $FFEF                                  ; monitor subroutine to print character in Accumulator         LDX #$0C                              ; store character count  in X registerLoop     LDA message,X                         ; get a character from position x in message, store in Accumulator         JSR CharOut                         ; print a character to the screen (with high bit already set)         DEX                                        ; x = x -1         BNE loop                                ; if x not zero, got to loop         RTS                                        ; return from this subroutineMessage ASC #$8D                           ; ASCII CR with high bit set        ASC “DLROW OLLEH”        ; HELLO WORLD acsii text with high bit set

————Here is a C like interpretation of the program logic in case you are not at all familiar with 6502 Assembly.  

Char[stringLength] messageString = “\nDLROW OLLEH” // “HELLO WORLD is reverse order                                                                                           // this data is encoded beginning at 28C as                                                                                           // ASCII + $80 because Apple ][ sets high bit                                                                                           // for character output                                                                                           // location 297 = $C8 -$80 = $48 = 72 decimal                                                                                           // ASCII 72 = ‘H’ character                                                                                          // location 296 = $C5 -$80 = $45 = 69 decimal                                                                                           // ASCII 69 = ‘E’ character etcstringLength = 12                                                              x = stringLength                                                                  // LDX with length of stringRepeat                                                                                // top of loop begins at $282{                                                               currentChar = messageString[ x]                                       // LDA  $28B,x                                                                                           // get character from $28B + x.    PrintScreen( currentChar)                                                // JSR $FFEF  x = x -1                                                                              // decrement x,  prepare for next char} until (x=0)                                                                          // BNE $282    , repeat loop as needed                              Exit subroutine                                                                    // RTS.

Here is really great source on 6502 assembly as related to the Apple I.  It s much longer, but more thorough than my answer here.

https://www.applefritter.com/replica/chapter6

Char[stringLength] messageString = “\nDLROW OLLEH” // “HELLO WORLD is reverse order with CR                                                   // this data is encoded beginning at 28C as                                                   // ASCII + $80 because Apple ][ sets high bit                                                   // for character output                                                   // location 297 = $C8 -$80 = $48 = 72 decimal                                                   // ASCII 72 = ‘H’ character                                                   // location 296 = $C5 -$80 = $45 = 69 decimal                                                   // ASCII 69 = ‘E’ character etc                                                     x = stringLength                                  // LDX with length of stringRepeat                                            // top of loop begins at $282{                                                               currentChar = messageString[ x]                 // LDA  $28B,x                                                  // get character from $28B + x.    PrintScreen( currentChar)                       // JSR $FFEF  x = x -1                                        // decrement x,  prepare for next char} until (x=0)                                     // BNE $282    , repeat loop as needed                              Exit subroutine                                   // RTS

Here is really great source on 6502 assembly as related to the Apple I.  It s much longer, but more thorough than my answer here.

      https://www.applefritter.com/replica/chapter6

 

 

Offline
Last seen: 8 hours 12 min ago
Joined: Nov 29 2020 - 19:48
Posts: 88
copy the above code into a

copy the above code into a fixed width editor and it will look a lot better.  The editor here sort of scrambles it up.

mmphosis's picture
Offline
Last seen: 2 days 16 hours ago
Joined: Aug 18 2005 - 16:26
Posts: 388
"\nDLROW OLLEH" ; string reversed and high bit set

The 1's and 0's are comments output by the assembler showing hex codes D2 CF and D7 in binary which are "DLR" as ASCII characters with the high bit set. The last 12 bytes are data: HELLO WORLD reversed with the high bit set. The code won't work as it's origin is $0000.

The first line should be:

* = $0280

Or, in the assembler that I like to use, the equivilent would be:

    org $0280

I should know, I wrote this assembly code many years ago

https://web.archive.org/web/20160419152215/http://hoop-la.ca/apple2/2008/retrochallenge.net.html

24 bytes!

and an Apple-1 emulator

https://www.applefritter.com/node/22285

 

 

 

 

Offline
Last seen: 6 hours 58 min ago
Joined: Mar 1 2019 - 04:38
Posts: 99
Each pair is an 8 bit number,

Each pair is an 8 bit number, thats eight 1's and 0's from 00000000 to 11111111 in binary (ie only 0's and 1's can be used)

 

If we use Hexidecimal instead of decimal we can represent each of the four bits by a number from 0 to F where 0=0000 and F=1111

So 00 = 0 decimal and 00000000 in binary and FF = 255 in decimal and 11111111 in hexidecimal

This is handy because we can look at a Hex number and divide it into two and more easily manipulate it. ie FF means 11111111 and F0 means 11110000.

 

So the first number pair A2 = 10100010 or 162. (note that A in binary is 1010 and 2 is 0010, not needed now but its why we use hex)

 

Now what do they mean, that depends on what the CPU is expecting as it reads them. When you type 280R, the CPU goes to the address (ie the place in memory that the numbers you typed are stored) and start interpreting the numbers it finds there.

 

At first it expects an instruction and the code A2 is interpreted as 'load the X register with the number in the next memory location' and this is written in shorthand as LDX # where LD= load, X= the x register and #=the next memory location (or immediate in computer speak)

When it processes this command, it then expects the next value in memory to be the number to load into the CPU's X register,

 

so A2 0C becomes in short hand LDX #$0C (the $ is used to show the reader than the 0C is a hexidecimal number) which means, load X with 12 decimanl (0C in hex means 12 in decimal)

 

The CPU then continues and expects the next memory to be a command and so on

 

A2 0C        LDX #$0C           as above, Load X register with 0C

BD 8B 02   LDA $028B,X      A new command which means Load the A register, but this time from the memory location 028B

 

There are many commands that the CPU uses and you really need to read a book. There is an online tutorial which might help but I haven't used it. 

 

https://skilldrick.github.io/easy6502/

 

 

Online
Last seen: 45 min 10 sec ago
Joined: Jun 29 2018 - 16:55
Posts: 223
This is definitely the era of

This is definitely the era of stuff where physical books are the way to go IMHO.

 

I have this one on hand and it's been a good resource for someone like myself without extensive background in assembly. 

 

https://www.amazon.com/Assembly-Lines-Complete-Roger-Wagner/dp/1312089407

Offline
Last seen: 6 hours 58 min ago
Joined: Mar 1 2019 - 04:38
Posts: 99
I learnt 6502 assembly with a

I learnt 6502 assembly with a BBC micro and Ian Birnbaum's Assembly language programming on the BBC micro.

 

Its a great way to learn as the assembler is built into the BASIC interpreter and the book really takes you through step by step. I suppose it would work on an emulator too.

 

https://bbc.godbolt.org

 

and the book is actually available here

 

https://stardot.org.uk/forums/viewtopic.php?t=13722

Log in or register to post comments