Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7571979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:48:20+00:00 2026-05-30T15:48:20+00:00

How can I print out a 2D array in ARM assembly? I’m trying to

  • 0

How can I print out a 2D array in ARM assembly?
I’m trying to take each row and then turn it into a null terminated string but it only prints out the first number. How can I move to the next number?

I was told this:To print the array it’s best to write a subroutine that loops through the array printing it one element at a time. printf only takes one argument and as in assembly language an array is just a load of numbers printf will only print the first one. Alternately you could write a subroutine that makes the board into a null terminated string. In either case the subroutine can both print the board and format it nicely.

But I only understand how to do it this way:

    AREA    Countdown, CODE, READONLY
IMPORT  main
IMPORT  getkey
IMPORT  sendchar
IMPORT  printf
EXPORT  start

start

    LDR R3, = teststr
    LDR R4, = array
wh1     LDRB R0, [R4]
    CMP R0, #0
    BEQ stop
    ADD R0, R0, #0X30
    STRB R0, [R3]
    ADD R3, R3, #1
    ADD R4, R4, #1  
    B wh1



stop B stop

AREA    Strings, DATA, READWRITE


teststr DCB "",0


array DCD 6, 3, 8, 2, 5, 2, 9, 1
     DCD 3, 7, 2, 8, 5, 7, 2, 6
     DCD 2, 4, 7, 4, 2, 6, 7, 4
     DCD 1, 9, 3, 2, 9, 5, 6, 8
     DCD 7, 5, 3, 7, 5, 8, 2, 1




END                 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:48:22+00:00Added an answer on May 30, 2026 at 3:48 pm

    Your program has several problems associated with it. One is that you’re not reserving space for the destination string, so you will be writing on unallocated memory. The other is that you’re not outputting a newline character.

    ROW_LENGTH equ 8
    
    start
    
        ldr r3, = teststr
        ldr r4, = array
        mov r2, #ROW_LENGTH-1   ; numbers displayed per row
    wh1 ldrb r0, [r4],#1
        orrs r0,r0,#0x30  ; add '0' to our digit
        bmi  end_of_data  ; end of source data
        strb r0,[r3],#1
        subs r2,r2,#1
        moveq r1,#0xd ; carriage return
        streqb r1,[r3],#1
        moveq r1,#0xa ; line feed
        streqb r1,[r3],#1
        moveq r2,#ROW_LENGTH-1  ; reset row counter
        b wh1
    end_of_data mov r0,#0   ; store string terminator
        strb r0,[r3]
        ; your return address in LR will no longer be preserved after the call to printf
        ; so you need to push/pop it to return to the caller
        ldr r0,=teststr   ; print the output
        bl  printf
    
    teststr DCB "                                                                      ",0
    
    
    array DCD 6, 3, 8, 2, 5, 2, 9, 1
         DCD 3, 7, 2, 8, 5, 7, 2, 6
         DCD 2, 4, 7, 4, 2, 6, 7, 4
         DCD 1, 9, 3, 2, 9, 5, 6, 8
         DCD 7, 5, 3, 7, 5, 8, 2, 1
         DCD -1       ; array terminator
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to iterate through all nodes, so I can print them out for
My assignment is to take an array of numbers and put it into ARM
In the code below, I am trying to print out a 1-column, 25-row table,
I have an array of objects and I can print them out, so I
Hi I'm trying to make an ordered list print out from an array. This
I'm trying to simply print out the values contained in an array. I have
In Mustache can I print out the name of an associative array key instead
I can print out a date nicely based on the user's locale. But how
Can i print out a url /admin/manage/products/add of a certain view in a template?
Can a Java Applet able to print out text/html easily to standard printer driver(s)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.