user1575528
user1575528

Reputation: 55

How do I print out a value in assembly language

I'm trying to print int "1" from a variable in LC3

I have:

COUNTER .FILL #1

LD R1, COUNTER

PUTC

but this prints "'0" (apostrophe zero)

Upvotes: 0

Views: 2322

Answers (1)

Patrick
Patrick

Reputation: 740

To print in lc3, there are two easy system routines available to use.

1) PUTS - "Write a string of ASCII characters to the console display. The characters are contained in consecutive memory locations, one character per memory location, starting with the address specified in R0. Writing terminates with the occurrence of x0000 in a memory location"*

2) OUT - "Write a character in R0[7:0] to the console display."*

Since you're just printing one character, you can use the OUT routine like so:

COUNTER .FILL #1
LD R0, COUNTER
OUT

Note the register is R0, not R1 like you had.

You could also use PUTS here, but PUTS will print until it finds x0000 in the next memory location. So for one character, using OUT is safer.

*See http://highered.mcgraw-hill.com/sites/dl/free/0072467509/104653/PattPatelAppA.pdf

Upvotes: 1

Related Questions