Answer to Question #284983 in Assembler for Nebil

Question #284983

Create an array of size 10. Take inputs from the user and populate the array. The inputs will be numerical values ranging from [1-9]. Now, you are to find all the pairs of numbers whose sum is equal to 10.


If there are no such pairs then print “SORRY! No Such Pairs”


Remember that a number can be used to form multiple pairs



Sample Input 01: 

1 2 3 4 5 6 7 8 9 1


Sample Output 01:

19

28

37

46


Sample Input 02: 

1 2 3 4 5 1 2 3 4 1


Sample Output 02:

SORRY! No Such Pairs




1
Expert's answer
2022-01-07T01:50:09-0500
;MS Visual Studio 2017
INCLUDE irvine32.inc
.data
number        BYTE    0
array         BYTE    10 DUP(0)
arrayNew     BYTE    10 DUP(0)
flag        BYTE    0

msgNum        BYTE "Enter a ten-digit string separated by a space  (1-9): ",0
MAX = 20                     ;max chars to read
stringIn    BYTE MAX+1 DUP (?)  ;room for null
msgSorry    BYTE "SORRY! No Such Pairs" ,0

.code
main PROC
    cld
    call readArray
    
    mov ecx, 10                ; counter
    mov esi, offset array
    mov edi, offset arrayNew
    call writeNewArray

LSum10:
    mov eax,0
    stosb
    lodsb
    mov number, al
    call sum10
    loop LSum10

    cmp flag,0
    jne _quit
    mov edx, OFFSET msgSorry
    call WriteString    
_quit:
    call crlf
    call crlf
    exit
    main ENDP
;**************************
sum10 PROC
    push ecx
    push esi
    push edi
    mov bl, number
    mov ecx, 10
    mov esi, OFFSET arrayNew
loopSum:
    lodsb
    mov bh, al
 
    add al,bl
    cmp al,10
    jne nextLoop

    mov al, bl
    call writeDec
    mov al, bh
    call writeDec
    call crlf
    inc flag

nextLoop:
     loop loopSum
    pop edi
    pop esi
    pop ecx
    ret
sum10 ENDP
;**************************
    writeNewArray PROC
    push ecx
    push esi
    push edi

    mov ecx,10
    mov esi, OFFSET array
    mov edi, OFFSET arrayNew
l1:    lodsb
    stosb
loop l1

    pop edi
    pop esi
    pop ecx
    ret
writeNewArray ENDP
;**************************************
readArray PROC
    mov  edx,OFFSET msgNum        ; address of message
    call WriteString            ; Writes a null-terminated string

    mov  edx, OFFSET stringIn
    mov  ecx, MAX            ;buffer size - 1
    call ReadString
    mov ecx,10
    mov edi, OFFSET array
    mov esi, OFFSET stringIn
readArr:
    lodsb
    sub al,'0'
    stosb
    inc esi
    loop readArr
    ret
readArray ENDP
END main

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS