How to resolve the algorithm Formatted numeric output step by step in the ARM Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Formatted numeric output step by step in the ARM Assembly programming language

Table of Contents

Problem Statement

Express a number in decimal as a fixed-length string with leading zeros.

For example, the number   7.125   could be expressed as   00007.125.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Formatted numeric output step by step in the ARM Assembly programming language

Source code in the arm programming language

/* ARM assembly Raspberry PI  */
/*  program formatNum.s   */
/* use C library printf  ha, ha, ha !!! */
/* Constantes               */
.equ EXIT,   1                         @ Linux syscall
/* Initialized data */
.data
szFormat1:         .asciz " %09.3f\n"
.align 4
sfNumber:          .double  0f-7125E-3
sfNumber1:         .double  0f7125E-3

/* UnInitialized data */
.bss 
.align 4

/*  code section */
.text
.global main 
main:                                   @ entry of program
    push {fp,lr}                        @ saves registers

    ldr r0,iAdrszFormat1                @ format
    ldr r1,iAdrsfNumber                 @ number address
    ldr r2,[r1]                         @ load first 4 bytes
    ldr r3,[r1,#4]                      @ load last 4 bytes
    bl printf                           @ call C function !!!
    ldr r0,iAdrszFormat1
    ldr r1,iAdrsfNumber1
    ldr r2,[r1]
    ldr r3,[r1,#4]
    bl printf



100:                                    @ standard end of the program
    mov r0, #0                          @ return code
    pop {fp,lr}                         @restaur  registers
    mov r7, #EXIT                       @ request to exit program
    swi 0                               @ perform the system call

iAdrszFormat1:           .int szFormat1
iAdrsfNumber:            .int sfNumber
iAdrsfNumber1:           .int sfNumber1

  

You may also check:How to resolve the algorithm Factors of an integer step by step in the Kotlin programming language
You may also check:How to resolve the algorithm 24 game/Solve step by step in the Simula programming language
You may also check:How to resolve the algorithm Sierpinski pentagon step by step in the Processing programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the F# programming language
You may also check:How to resolve the algorithm Count the coins step by step in the Python programming language