ARM Assembly how to print numbers instead of their ascii rep

Ask questions about Arch Linux ARM. Please search before making a new topic.

ARM Assembly how to print numbers instead of their ascii rep

Postby kananJarrus » Tue Aug 13, 2019 9:20 am

I am new to arm assembly, i'm trying to print integer to screen instead of their ASCII representation of that number. Below is the code which i'm trying with instead of printing 99 i'm getting 'c'.

$this->bbcode_second_pass_quote('', '.')global _start
.text
_start:

@ write to num variable
_write:
mov r8, #99
ldr r9, =num
str r8, [r9]

@read from num variable and print to screen
_read:
mov r7, #4 @ syscall
mov r0, #1 @ std output
ldr r1, =num @ starting address
mov r2, #2 @ number of character to print
swi 0 @ interrupt

_end:
mov r7, #1
swi 0

.data
num: .word 0


I have checked online resources which has numerous examples of printing strings but not numbers.

$this->bbcode_second_pass_quote('', ' ') [root@alarmpi]# make
as -o num.o num.s
ld - num num.o
[root@alarmpi ]# ./num
c


Kindly let me know how to output numbers using ARM assembly (possibly without using C libraries).

Thank You.
Last edited by moonman on Tue Aug 13, 2019 9:33 pm, edited 1 time in total.
Reason: Removed font enlargement.
kananJarrus
 
Posts: 2
Joined: Tue Aug 13, 2019 9:14 am

Re: ARM Assembly how to print numbers instead of their ascii

Postby summers » Tue Aug 13, 2019 3:46 pm

Well its years since I did assembly. But what I'd do is split each 8bit byte into two 4bit values, which you can do with the shift operators.

Then for the 4bit value print a character from the lookup table '0123456789abcdef'.

My machine code is old 6502 stuff, (well and also sharp PC1403) - and that was all doable, with careful register use. I'd expect on an arm it shouldn't be any harder ...
summers
 
Posts: 995
Joined: Sat Sep 06, 2014 12:56 pm


Return to User Questions

Who is online

Users browsing this forum: No registered users and 18 guests