199k views
2 votes
Arm Assembly

Print an Asterisk Diamond according to the size
given in constant SIZE, into the UART terminal. For example, if the
SIZE is 3, output
would be:
*
* *
* * *
* *
*

1 Answer

6 votes

Final answer:

To print an asterisk diamond in Arm Assembly, you can use nested loops to control the number of spaces and asterisks in each row.

The outer loop controls the number of rows, and the inner loops control the number of spaces and asterisks in each row. Here's an example code:

Step-by-step explanation:

To print an asterisk diamond in Arm Assembly according to the given size, you can use nested loops. The outer loop controls the number of rows, and the inner loops control the number of spaces and asterisks in each row. Here's an example code:

AREA Diamond, CODE, READONLY

ENTRY

MOV R0, #3

BL print_diamond

B done

print_diamond:
PUSH {r4, r5, r6, lr}
SUB SP, SP, #16

MOV R4, #0
inner_loop:
CMP R4, R0
BGT outer_loop_done
MOV R5, R0
SUB R6, R5, R4
outer_loop:
MOV R1, #0
CMP R1, R6
BGT inner_loop_done
MOV R2, R5
SUB R3, R2, R6
MOV R7, R4
CMP R7, R6
ADDT R7, R3
CMP R4, R3
LTT R7, R4
CMP R4, R3
ADDT R7, R4
CMP R4, R3
LTT R7, R7

ADD R2, R7
ADD R1, R2
CMP R1, R5
ADDT R1, R3

CMP R1, R5
LTT R1, R3
CMP R5, R3

ADD R2, R4
ADD R1, R2
CMP R1, R5
LTT R1, R3

CMP R1, R5
LTT R1, R3
ADD R1, R2
CMP R1, R5
ADDT R1, R3

MOV R8, #' '
ADD R1, R8
MOV R8, #'\\'

ADD R2, R8
MOV R1, #'\'

ADD R0, R1
CMP R0, #' '

B outer_loop
outer_loop_done:
ADD R4, #1
B inner_loop
inner_loop_done:
ADD R4, #1
B inner_loop
done:
MOV R0, #4

ADD SP, SP, #16
POP {r4, r5, r6, lr}
MOV pc, lr
END

User Nitesh Tiwari
by
8.4k points

Related questions

asked May 24, 2024 2.9k views
Clay Hinson asked May 24, 2024
by Clay Hinson
7.8k points
1 answer
1 vote
2.9k views
1 answer
2 votes
137k views