0

So in Pep 9 there is an example of a way to print out the .ascii "hi".

;File: fig0433.peph   
;Computer Systems, Fifth edition  
;Figure 4.33

         LDBA    0x000D,d    ;Load byte accumulator 'H'
         STBA    0xFC16,d    ;Store byte accumulator output device
         LDBA    0x000E,d    ;Load byte accumulator 'i'
         STBA    0xFC16,d    ;Store byte accumulator output device
         STOP                ;Stop
        .ASCII  "Hi"        ;ASCII "Hi" characters
        .END

I tried to use the name logic to write my name but the output showed weird characters: Ñ
Could someone explain to me why this logic does not work and I would like someone to steer me in the right direction.

;Stan Warford   
;May 1, 2016   
;A program to output "Hi"   
;   

         LDBA    0x000C,d    ;Load byte accumulator 'A'
         STBA    0xFC16,d    ;Store byte accumulator output device
         LDBA    0x000D,d    ;Load byte accumulator 'r'
         STBA    0xFC16,d    ;Store byte accumulator output device
         LDBA    0x000E,d    ;Load byte accumulator 'i'
         STBA    0xFC16,d    ;Store byte accumulator output device
         LDBA    0x000F,d    ;Load byte accumulator 'e'
         STBA    0xFC16,d    ;Store byte accumulator output device
         LDBA    0x0010,d    ;Load byte accumulator 'l'
         STBA    0xFC16,d    ;Store byte accumulator output device
         STOP                ;Stop
         .ASCII  "Ariel"        ;ASCII "Ariel" characters
         .END
Fred Larson
  • 60,987
  • 18
  • 112
  • 174
IRedSonI
  • 1
  • 1
  • 2
  • 0xd is not the ASCII code for `'H'`. Is that a load from a memory address instead of a load-immediate? What source code did you build this from? You should probably have a label at the start of your string so you can get the assembler to reference addresses in it. – Peter Cordes May 02 '18 at 03:00
  • Sorry I fixed it. Yes it is loading a byte from memory using the direct addressing mode. The first set of assembly code was an example in the book. I copy/pasted onto pep9, ran it, and it printed out "Hi" – IRedSonI May 02 '18 at 03:11
  • The addresses are hard-coded, but your 2nd version has more instruction bytes before the string. So the start of the string is at a different address. This is why normal assembly languages use labels e.g. `msg: .ASCII "Ariel"`, so you can write instructions like `ldba msg+2, d` and the assembler will fill in the right address once it knows where in memory `msg` starts. – Peter Cordes May 02 '18 at 03:17
  • So is "msg" like a variable? Why did you write msg+2? – IRedSonI May 02 '18 at 03:36
  • Yeah, asm doesn't have variables per-se, but yeah a label + some bytes of storage are what a C compiler would use to implement `static char msg[] = "Ariel"`; I wrote `msg+2` to show you that you can use offsets from a label, instead of just the base address itself; you don't have to put a label on each byte in the string separately. (But really, if you're going to use one instruction per byte anyway, you don't need the string in memory. Use `lda,i` to use the operand as an immediate and put it into AC directly, instead of as a memory address: http://suffolk.li/cst111/19cst111/pep8.html) – Peter Cordes May 02 '18 at 03:40
  • Hmm okay. For some odd reason when I add the line LDBA msg+2, d the compiler says that I require an addressing mode – IRedSonI May 02 '18 at 03:54
  • I'm not familiar with PEP8/PEP9 tools, I don't know if they actually do support labels, or if you have to calculate the addresses yourself. Or if there's different syntax. I'm just saying that the "normal" solution to this problem in nice assemblers for real platforms is labels. Hopefully PEP9 has labels, but I don't guarantee it, and I don't know if there's special syntax! Consult the manual or google for PEP8 labels or something – Peter Cordes May 02 '18 at 03:56
  • 1
    The code runs without problems by just writing LDBA msg, d and it outputs 0000 in the console. There might be different syntax to do LDBA msg+2, d. – IRedSonI May 02 '18 at 04:00
  • Interesting. Anyway like I said, I'd suggest `LDA 'A', i` to put the ASCII value `A` directly into AC, without loading anything from memory, if you're going to use a separate instruction for every character anyway. (Hopefully that's the right syntax). Or use a word immediate, then char store / right shift / char store? Eh, that's hardly better. – Peter Cordes May 02 '18 at 04:02
  • Alrighty thank you for your help – IRedSonI May 02 '18 at 04:08

0 Answers0