How to resolve the algorithm Ethiopian multiplication step by step in the ARM Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Ethiopian multiplication step by step in the ARM Assembly programming language

Table of Contents

Problem Statement

Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving.

Method:

For example:   17 × 34 Halving the first column: Doubling the second column: Strike-out rows whose first cell is even: Sum the remaining numbers in the right-hand column: So 17 multiplied by 34, by the Ethiopian method is 578.

The task is to define three named functions/methods/procedures/subroutines:

Use these functions to create a function that does Ethiopian multiplication.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Ethiopian multiplication step by step in the ARM Assembly programming language

Source code in the arm programming language

/* ARM assembly Raspberry PI  */
/*  program multieth.s   */

 /* REMARK 1 : this program use routines in a include file 
   see task Include a file language arm assembly 
   for the routine affichageMess conversion10 
   see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes                       */
/************************************/
.include "../constantes.inc"

/*********************************/
/* Initialized data              */
/*********************************/
.data
szMessResult:         .asciz "Result : "
szMessStart:          .asciz "Program 32 bits start.\n"
szCarriageReturn:     .asciz "\n"
szMessErreur:         .asciz "Error overflow. \n"
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss
sZoneConv:             .skip 24
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                            @ entry of program 
    ldr r0,iAdrszMessStart
    bl affichageMess
    mov r0,#17
    mov r1,#34
    bl multEthiop
    ldr r1,iAdrsZoneConv
    bl conversion10              @ decimal conversion
    mov r0,#3                    @ number string to display
    ldr r1,iAdrszMessResult
    ldr r2,iAdrsZoneConv         @ insert conversion in message
    ldr r3,iAdrszCarriageReturn
    bl displayStrings            @ display message

100:                              @ standard end of the program 
    mov r0, #0                    @ return code
    mov r7, #EXIT                 @ request to exit program
    svc #0                        @ perform the system call
iAdrszCarriageReturn:        .int szCarriageReturn
iAdrsZoneConv:               .int sZoneConv
iAdrszMessResult:            .int szMessResult
iAdrszMessErreur:            .int szMessErreur
iAdrszMessStart:             .int szMessStart
/******************************************************************/
/*     Ethiopian multiplication                                  */ 
/******************************************************************/
/*  r0  first factor */
/*  r1   2th  factor  */
/*  r0 return résult  */
multEthiop:
    push {r1-r3,lr}            @ save registers
    mov r2,#0                  @ init result
 1:                            @ loop
    cmp r0,#1                  @ end ?
    blt 3f
    ands r3,r0,#1              @ 
    addne r2,r1                @ add factor2 to result
    lsr r0,#1                  @ divide factor1 by 2
    lsls r1,#1                 @ multiply factor2 by 2
    bcs 2f                     @ overflow ?
    b 1b                       @ or loop
 2:                            @ error display 
    ldr r0,iAdrszMessErreur
    bl affichageMess
    mov r2,#0
 3:
    mov r0,r2                  @ return result
    pop {r1-r3,pc}
/***************************************************/
/*   display multi strings                    */
/***************************************************/
/* r0  contains number strings address */
/* r1 address string1 */
/* r2 address string2 */
/* r3 address string3 */
/* other address on the stack */
/* thinck to add  number other address * 4 to add to the stack */
displayStrings:            @ INFO:  displayStrings
    push {r1-r4,fp,lr}     @ save des registres
    add fp,sp,#24          @ save paraméters address (6 registers saved * 4 bytes)
    mov r4,r0              @ save strings number
    cmp r4,#0              @ 0 string -> end
    ble 100f
    mov r0,r1              @ string 1
    bl affichageMess
    cmp r4,#1              @ number > 1
    ble 100f
    mov r0,r2
    bl affichageMess
    cmp r4,#2
    ble 100f
    mov r0,r3
    bl affichageMess
    cmp r4,#3
    ble 100f
    mov r3,#3
    sub r2,r4,#4
1:                         @ loop extract address string on stack
    ldr r0,[fp,r2,lsl #2]
    bl affichageMess
    subs r2,#1
    bge 1b
100:
    pop {r1-r4,fp,pc}


/***************************************************/
/*      ROUTINES INCLUDE                           */
/***************************************************/
.include "../affichage.inc"

  

You may also check:How to resolve the algorithm Look-and-say sequence step by step in the Yabasic programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the Delphi programming language
You may also check:How to resolve the algorithm Faulhaber's triangle step by step in the C programming language
You may also check:How to resolve the algorithm EKG sequence convergence step by step in the jq programming language
You may also check:How to resolve the algorithm Word ladder step by step in the Perl programming language