Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
the problem is:


In this Question , you need to implement a simple encryption and decryption algorithm in ARM assembly. Given a text
message (string) stored in the memory, the encryption program gets the ASCII code of each character and apply this method

*the method is: Invert the first and the second bits of the ASCII code of each character.

The encrypted character is stored back in a different location in the memory.

you have to write two assembly programs; encryption and decryption. The encryption program takes the text message stored in the memory at specific address and applies the encryption method on every single character and then stores the encrypted message in a different location in the memory. The decryption program takes the encrypted
message and applies the reverse of the encryption process, which is called the key.

What I have tried:

there are many solutions that I dont know which of them is the correct one ..and I don't know if they are in Arm or ox86 assembly since I have started studying Assembly from few days
please tell me which of them is correct in Arm assembly and I want you two know that all of these solutions missing something ( missing applying the invert method that the question asked to apply it )



the first sol:


segment code

start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,stacktop

%define encoderkey 'hello'
%strlen enkey encoderkey

main1:

	mov dx,info1
	mov ah,9
	int 0x21

	mov dx,info2
	mov ah,9
	int 0x21

	mov dx,blankline
	mov ah,9
	int 0x21

	mov dx,message1
	mov ah,9
	int 0x21

	mov dx,message2
	mov ah,9
	int 0x21

	mov dx,blankline
	mov ah,9
	int 0x21

select:

	mov ah,00
	int 16h

	mov dl,al
        
      	cmp al, '1'           
	jz encrypt

	cmp al,'2'
	jz decrypt

encrypt:

	mov dx,message3
	mov ah,9
	int 0x21

	mov dx,blankline
	mov ah,9
	int 0x21

main_encrypt:
	mov ah,00
	int 16h

	mov dl,al
        
      	cmp al, 'q'           
	jz done

	mov ah,enkey
	add dl, ah

	mov ah,2
	int 0x21

jmp main_encrypt

decrypt:

	mov dx,message4
	mov ah,9
	int 0x21

	mov dx,blankline
	mov ah,9
	int 0x21

main_decrypt:
	mov ah,00
	int 16h

	mov dl,al
        
      	cmp al, 'q'           
	jz done

	mov ah,-enkey
	add dl, ah

	mov ah,2
	int 0x21

jmp main_decrypt

done:
	mov ax,0x4c00
	int 0x21

segment data

info1: db 'Huo CoDec - Programmed by Spiros Kakos (Huo)', 13, 10, '$'
info2: db '(c) Copyright 2005 - All rights reserved', 13, 10, '$'
blankline: db ' ', 13, 10, '$'
message1: db '1 - Encrypt message', 13, 10, '$'
message2: db '2 - Decrypt message', 13, 10, '$'
message3: db 'Encrypting mode (q to exit)...', 13, 10, '$'
message4: db 'Decrypting mode (q to exit)...', 13, 10, '$'

segment stack stack
resb 64
stacktop:




the second sol:


.LC0:
        .ascii  "\012Please enter a string:\011\000"
.LC1:
        .ascii  "\012Please choose following options:\000"
.LC2:
        .ascii  "1 = Encrypt the string.\000"
.LC3:
        .ascii  "2 = Decrypt the string.\000"
.LC4:
        .ascii  "%d\000"
.LC5:
        .ascii  "\012Encrypted string: %s\012\000"
.LC6:
        .ascii  "\012Decrypted string: %s\012\000"
.LC7:
        .ascii  "\012Error\000"
main:
        stmfd   sp!, {fp, lr}
        add     fp, sp, #4
        sub     sp, sp, #112
        ldr     r3, .L13
        mov     r0, r3
        bl      printf
        sub     r3, fp, #112
        mov     r0, r3
        bl      gets
        ldr     r0, .L13+4
        bl      puts
        ldr     r0, .L13+8
        bl      puts
        ldr     r0, .L13+12
        bl      puts
        ldr     r2, .L13+16
        sub     r3, fp, #12
        mov     r0, r2
        mov     r1, r3
        bl      __isoc99_scanf
        ldr     r3, [fp, #-12]
        cmp     r3, #1
        beq     .L3
        cmp     r3, #2
        beq     .L4
        b       .L12
.L3:
        mov     r3, #0
        str     r3, [fp, #-8]
        b       .L5
.L7:
        mvn     r3, #107
        ldr     r2, [fp, #-8]
        sub     r0, fp, #4
        add     r2, r0, r2
        add     r3, r2, r3
        ldrb    r3, [r3, #0]    @ zero_extendqisi2
        add     r3, r3, #3
        and     r2, r3, #255
        mvn     r3, #107
        ldr     r1, [fp, #-8]
        sub     r0, fp, #4
        add     r1, r0, r1
        add     r3, r1, r3
        strb    r2, [r3, #0]
        ldr     r3, [fp, #-8]
        add     r3, r3, #1
        str     r3, [fp, #-8]
.L5:
        ldr     r3, [fp, #-8]
        cmp     r3, #99
        bgt     .L6
        mvn     r3, #107
        ldr     r2, [fp, #-8]
        sub     r1, fp, #4
        add     r2, r1, r2
        add     r3, r2, r3
        ldrb    r3, [r3, #0]    @ zero_extendqisi2
        cmp     r3, #0
        bne     .L7
.L6:
        ldr     r2, .L13+20
        sub     r3, fp, #112
        mov     r0, r2
        mov     r1, r3
        bl      printf
        b       .L8
.L4:
        mov     r3, #0
        str     r3, [fp, #-8]
        b       .L9
.L11:
        mvn     r3, #107
        ldr     r2, [fp, #-8]
        sub     r0, fp, #4
        add     r2, r0, r2
        add     r3, r2, r3
        ldrb    r3, [r3, #0]    @ zero_extendqisi2
        sub     r3, r3, #3
        and     r2, r3, #255
        mvn     r3, #107
        ldr     r1, [fp, #-8]
        sub     r0, fp, #4
        add     r1, r0, r1
        add     r3, r1, r3
        strb    r2, [r3, #0]
        ldr     r3, [fp, #-8]
        add     r3, r3, #1
        str     r3, [fp, #-8]
.L9:
        ldr     r3, [fp, #-8]
        cmp     r3, #99
        bgt     .L10
        mvn     r3, #107
        ldr     r2, [fp, #-8]
        sub     r1, fp, #4
        add     r2, r1, r2
        add     r3, r2, r3
        ldrb    r3, [r3, #0]    @ zero_extendqisi2
        cmp     r3, #0
        bne     .L11
.L10:
        ldr     r2, .L13+24
        sub     r3, fp, #112
        mov     r0, r2
        mov     r1, r3
        bl      printf
        b       .L8
.L12:
        ldr     r0, .L13+28
        bl      puts
.L8:
        mov     r3, #0
        mov     r0, r3
        sub     sp, fp, #4
        ldmfd   sp!, {fp, pc}
.L13:
        .word   .LC0
        .word   .LC1
        .word   .LC2
        .word   .LC3
        .word   .LC4
        .word   .LC5
        .word   .LC6
        .word   .LC7





the third sol:

 DATA SEGMENT
    MSG1 DB 10,13,’ENTER STRING HERE :- $’   
    MSG2 DB 10,13,’ENCRYPTED STRING IS :- $’
    MSG3 DB 10,13,’DECRYPTED STRING IS : $’
   
    P1 LABEL BYTE
    M1 DB 0FFH
    L1 DB ?
    P11 DB 0FFH DUP (‘$’)
   
DATA ENDS


 
DISPLAY MACRO MSG
    MOV AH,9
    LEA DX,MSG
    INT 21H
ENDM   
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START:
        MOV AX,DATA
        MOV DS,AX                
               
        DISPLAY MSG1
       
        LEA DX,P1
        MOV AH,0AH    
        INT 21H
                      
        LEA SI,P11
        MOV CL,L1
        CALL ENCRYPT
       
        DISPLAY MSG2
        DISPLAY P11
                               
        LEA SI,P11
        MOV CL,L1
        CALL ENCRYPT
       
        DISPLAY MSG3
        DISPLAY P11
       
        MOV AH,4CH
        INT 21H
CODE ENDS


 
ENCRYPT PROC NEAR
        MOV CH,0       
CHECK1:
        CMP [SI],2FH
        JB DONE1
        CMP [SI],3AH
        JB NUM1
       
        CMP [SI],41H
        JB DONE1
        CMP [SI],5BH
        JB UPR1
       
        CMP [SI],61H
        JB DONE1
        CMP [SI],7BH
        JB LWR1
       
NUM1:    CMP [SI],35H
        JB LNUM1
        SUB [SI],05H
        JMP DONE1
   LNUM1:    
        ADD [SI],05H
        JMP DONE1   
       
UPR1:    CMP [SI],4EH
        JB LUPR1
        SUB [SI],0DH
        JMP DONE1
   LUPR1:    
        ADD [SI],0DH
        JMP DONE1


 
LWR1:    CMP [SI],6EH
        JB LLWR1
        SUB [SI],0DH
        JMP DONE1
   LLWR1:    
        ADD [SI],0DH
             
DONE1:       
        INC SI
        LOOP CHECK1
       RET
ENCRYPT ENDP

DECRYPT PROC NEAR
        MOV CH,0       
CHECK2:
        CMP [SI],2FH
        JB DONE2
        CMP [SI],3AH
        JB NUM2
       
        CMP [SI],41H
        JB DONE2
        CMP [SI],5BH
        JB UPR2
       
        CMP [SI],61H
        JB DONE2
        CMP [SI],7BH
        JB LWR2
       
NUM2:   CMP [SI],35H
        JB LNUM2
        ADD [SI],05H
        JMP DONE2
   LNUM2:    
        SUB [SI],05H
        JMP DONE2   
       
UPR2:    CMP [SI],4EH
        JB LUPR2
        ADD [SI],0DH
        JMP DONE2
   LUPR2:    
        SUB [SI],0DH
        JMP DONE2


 
LWR2:    CMP [SI],6EH
        JB LLWR2
        ADD [SI],0DH
        JMP DONE2
   LLWR2:    
        SUB [SI],0DH
             
DONE2:       
        INC SI
        LOOP CHECK2
       RET
DECRYPT ENDP
   
END START






the 4th sol:


int 21h
read1:mov si,offset chr
mov ah,01h
int 21h
mov [si],al
inc si
mov al,24h
mov [si],al
mov bx,00
mov si,offset buf
mov ax,00
mov di,offset chr
check:mov al,[si]
cmp al,[di]
je count
cmp al,'$'
je dis
inc si
jmp check
count:inc bl
inc si
jmp check
dis:mov strlen,bl
lea si,res
mov ax,00
mov al,strlen
call hex2asc
lea dx,msg3
mov ah,09h
int 21h
lea dx,res
mov ah,09h
int 21h
ou:mov ax,4c00h
int 21h
main endp
hex2asc proc near
push ax
push bx
push cx
push dx
push si
mov cx,00h
mov bx,0Ah
rpt1: mov dx,00
div bx
add dl,'0'
push dx
inc cx
cmp ax,0Ah
jge rpt1
add al,'0'
mov [si],al
rpt2: pop ax
inc si
mov [si],al
loop rpt2
inc si
mov al,'$'
mov [si],al
pop si
pop dx
pop cx
pop bx
pop ax
ret
hex2asc endp
end
     


Prg(strrev.asm)
Title reversing a string
dosseg
.model small
.stack
.data
msg1 db 13,10,"Enter a string with dolar symbol as a break:$"
msg2 db 13,10,"Reverse of a string is:$"
strg db 20 DUP(0)
restr db 20 DUP(0)
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
mov di,00
lea dx,msg1
mov ah,09h
int 21h
read:mov ah,01h
int 21h
cmp al,24h
je next
inc di
mov strg[di],al
jmp read
next: mov si,00
start:cmp di,0
je dmsg2
mov al,strg[di]
mov restr[si],al
inc si
dec di
jmp start
dmsg2:lea dx,msg2
mov ah,09h
int 21h
dis:mov al,restr[di]
cmp al,0
je ou
mov dl,al
mov ah,02h
int 21h
inc di
jmp dis
ou: mov ax,4c00h
int 21h
main endp




other sol:


encryption(std::basic_string<char, std::char_traits<char>, std::allocator<char> >):
        stmfd   sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}
        add     fp, sp, #32
        sub     sp, sp, #76
        str     r0, [fp, #-108]
        str     r1, [fp, #-96]
        mov     r3, sp
        str     r3, [fp, #-100]
        ldr     r0, [fp, #-96]
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const
        mov     r3, r0
        str     r3, [fp, #-60]
        ldr     r0, [fp, #-60]
        bl      __gnu_cxx::__enable_if<std::__is_integer<int>::__value, double>::__type std::sqrt<int>(int)
        mov     r2, r0
        mov     r3, r1
        mov     r0, r2
        mov     r1, r3
        bl      ceil
        mov     r2, r0
        mov     r3, r1
        mov     r0, r2
        mov     r1, r3
        bl      __aeabi_d2iz
        mov     r3, r0
        str     r3, [fp, #-80]
        ldr     r0, [fp, #-60]
        bl      __gnu_cxx::__enable_if<std::__is_integer<int>::__value, double>::__type std::sqrt<int>(int)
        mov     r2, r0
        mov     r3, r1
        mov     r0, r2
        mov     r1, r3
        bl      floor
        mov     r2, r0
        mov     r3, r1
        mov     r0, r2
        mov     r1, r3
        bl      __aeabi_d2iz
        mov     r3, r0
        str     r3, [fp, #-84]
        ldr     r3, [fp, #-108]
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor]
        ldr     r3, [fp, #-80]
        ldr     r2, [fp, #-84]
        mul     r2, r3, r2
        ldr     r3, [fp, #-60]
        cmp     r2, r3
        bge     .L2
        sub     r2, fp, #80
        sub     r3, fp, #84
        mov     r0, r2
        mov     r1, r3
        bl      int const& std::min<int>(int const&, int const&)
        mov     r3, r0
        ldr     r2, [r3, #0]
        ldr     r3, [fp, #-80]
        cmp     r2, r3
        movne   r3, #0
        moveq   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        beq     .L3
        ldr     r3, [fp, #-80]
        add     r3, r3, #1
        str     r3, [fp, #-80]
        b       .L2
.L3:
        ldr     r3, [fp, #-84]
        add     r3, r3, #1
        str     r3, [fp, #-84]
.L2:
        ldr     r3, [fp, #-80]
        sub     ip, r3, #1
        str     ip, [fp, #-64]
        mov     r3, ip
        mov     r0, r3
        mov     r1, #0
        mov     r2, #1
        mov     r3, #0
        adds    r2, r2, r0
        adc     r3, r3, r1
        mov     r1, r2, lsr #29
        mov     r5, r3, asl #3
        orr     r5, r1, r5
        mov     r4, r2, asl #3
        mov     r3, ip
        add     r3, r3, #1
        str     r3, [fp, #-104]
        ldr     r3, [fp, #-84]
        sub     lr, r3, #1
        str     lr, [fp, #-68]
        mov     r3, ip
        mov     r1, r3
        mov     r2, #0
        mov     r3, #1
        mov     r4, #0
        mov     r5, r1
        mov     r6, r2
        adds    r5, r5, r3
        adc     r6, r6, r4
        mov     r3, lr
        add     r3, r3, #1
        mov     r1, r3
        mov     r2, #0
        mul     r0, r1, r6
        mul     r3, r5, r2
        add     r0, r0, r3
        umull   r3, r4, r5, r1
        add     r0, r0, r4
        mov     r4, r0
        mov     r2, r3, lsr #29
        mov     sl, r4, asl #3
        orr     sl, r2, sl
        mov     r9, r3, asl #3
        mov     r3, ip
        mov     r1, r3
        mov     r2, #0
        mov     r3, #1
        mov     r4, #0
        mov     r5, r1
        mov     r6, r2
        adds    r5, r5, r3
        adc     r6, r6, r4
        mov     r3, lr
        add     r3, r3, #1
        mov     r1, r3
        mov     r2, #0
        mul     r0, r1, r6
        mul     r3, r5, r2
        add     r0, r0, r3
        umull   r3, r4, r5, r1
        add     r0, r0, r4
        mov     r4, r0
        mov     r2, r3, lsr #29
        mov     r8, r4, asl #3
        orr     r8, r2, r8
        mov     r7, r3, asl #3
        mov     r3, ip
        add     r3, r3, #1
        mov     r2, lr
        add     r2, r2, #1
        mul     r3, r2, r3
        add     r3, r3, #7
        add     r3, r3, #7
        mov     r3, r3, lsr #3
        mov     r3, r3, asl #3
        sub     sp, sp, r3
        mov     r3, sp
        add     r3, r3, #7
        mov     r3, r3, lsr #3
        mov     r3, r3, asl #3
        str     r3, [fp, #-72]
        ldr     r2, [fp, #-72]
        mov     r3, ip
        add     r3, r3, #1
        mov     r1, lr
        add     r1, r1, #1
        mul     r3, r1, r3
        mov     r0, r2
        mov     r1, #32
        mov     r2, r3
        bl      memset
        mov     r3, #0
        str     r3, [fp, #-40]
        mov     r3, #0
        str     r3, [fp, #-44]
        b       .L4
.L8:
        mov     r3, #0
        str     r3, [fp, #-48]
        b       .L5
.L7:
        ldr     r2, [fp, #-40]
        ldr     r3, [fp, #-60]
        cmp     r2, r3
        bge     .L6
        ldr     r3, [fp, #-40]
        ldr     r0, [fp, #-96]
        mov     r1, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int)
        mov     r3, r0
        ldrb    r2, [r3, #0]    @ zero_extendqisi2
        ldr     r1, [fp, #-72]
        ldr     r3, [fp, #-44]
        ldr     r0, [fp, #-104]
        mul     r3, r0, r3
        add     r1, r1, r3
        ldr     r3, [fp, #-48]
        add     r3, r1, r3
        strb    r2, [r3, #0]
.L6:
        ldr     r3, [fp, #-40]
        add     r3, r3, #1
        str     r3, [fp, #-40]
        ldr     r3, [fp, #-48]
        add     r3, r3, #1
        str     r3, [fp, #-48]
.L5:
        ldr     r3, [fp, #-80]
        ldr     r2, [fp, #-48]
        cmp     r2, r3
        movge   r3, #0
        movlt   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        bne     .L7
        ldr     r3, [fp, #-44]
        add     r3, r3, #1
        str     r3, [fp, #-44]
.L4:
        ldr     r3, [fp, #-84]
        ldr     r2, [fp, #-44]
        cmp     r2, r3
        movge   r3, #0
        movlt   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        bne     .L8
        mov     r3, #0
        str     r3, [fp, #-52]
        b       .L9
.L12:
        mov     r3, #0
        str     r3, [fp, #-56]
        b       .L10
.L11:
        ldr     r4, [fp, #-108]
        ldr     r2, [fp, #-108]
        ldr     r1, [fp, #-72]
        ldr     r3, [fp, #-56]
        ldr     r0, [fp, #-104]
        mul     r3, r0, r3
        add     r1, r1, r3
        ldr     r3, [fp, #-52]
        add     r3, r1, r3
        ldrb    r3, [r3, #0]    @ zero_extendqisi2
        sub     r1, fp, #76
        mov     r0, r1
        mov     r1, r2
        mov     r2, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)
        sub     r3, fp, #76
        mov     r0, r4
        mov     r1, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
        sub     r3, fp, #76
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        ldr     r3, [fp, #-56]
        add     r3, r3, #1
        str     r3, [fp, #-56]
.L10:
        ldr     r3, [fp, #-84]
        ldr     r2, [fp, #-56]
        cmp     r2, r3
        movge   r3, #0
        movlt   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        bne     .L11
        ldr     r3, [fp, #-52]
        add     r3, r3, #1
        str     r3, [fp, #-52]
.L9:
        ldr     r3, [fp, #-80]
        ldr     r2, [fp, #-52]
        cmp     r2, r3
        movge   r3, #0
        movlt   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        bne     .L12
        ldr     sp, [fp, #-100]
        ldr     r0, [fp, #-108]
        ldr     r0, [fp, #-108]
        sub     sp, fp, #32
        ldmfd   sp!, {r4, r5, r6, r7, r8, r9, sl, fp, pc}
        sub     r3, fp, #76
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L14
.L14:
        ldr     r3, [fp, #-108]
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L15
.L15:
        ldr     sp, [fp, #-100]
        bl      __cxa_end_cleanup
decryption(std::basic_string<char, std::char_traits<char>, std::allocator<char> >):
        stmfd   sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}
        add     fp, sp, #32
        sub     sp, sp, #76
        str     r0, [fp, #-108]
        str     r1, [fp, #-96]
        mov     r3, sp
        str     r3, [fp, #-100]
        ldr     r0, [fp, #-96]
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const
        mov     r3, r0
        str     r3, [fp, #-60]
        ldr     r0, [fp, #-60]
        bl      __gnu_cxx::__enable_if<std::__is_integer<int>::__value, double>::__type std::sqrt<int>(int)
        mov     r2, r0
        mov     r3, r1
        mov     r0, r2
        mov     r1, r3
        bl      ceil
        mov     r2, r0
        mov     r3, r1
        mov     r0, r2
        mov     r1, r3
        bl      __aeabi_d2iz
        mov     r3, r0
        str     r3, [fp, #-64]
        ldr     r0, [fp, #-60]
        bl      __gnu_cxx::__enable_if<std::__is_integer<int>::__value, double>::__type std::sqrt<int>(int)
        mov     r2, r0
        mov     r3, r1
        mov     r0, r2
        mov     r1, r3
        bl      floor
        mov     r2, r0
        mov     r3, r1
        mov     r0, r2
        mov     r1, r3
        bl      __aeabi_d2iz
        mov     r3, r0
        str     r3, [fp, #-68]
        ldr     r3, [fp, #-108]
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor]
        ldr     r3, [fp, #-64]
        sub     ip, r3, #1
        str     ip, [fp, #-72]
        mov     r3, ip
        mov     r0, r3
        mov     r1, #0
        mov     r2, #1
        mov     r3, #0
        adds    r2, r2, r0
        adc     r3, r3, r1
        mov     r1, r2, lsr #29
        mov     r5, r3, asl #3
        orr     r5, r1, r5
        mov     r4, r2, asl #3
        mov     r3, ip
        add     r3, r3, #1
        str     r3, [fp, #-104]
        ldr     r3, [fp, #-68]
        sub     lr, r3, #1
        str     lr, [fp, #-76]
        mov     r3, ip
        mov     r1, r3
        mov     r2, #0
        mov     r3, #1
        mov     r4, #0
        mov     r5, r1
        mov     r6, r2
        adds    r5, r5, r3
        adc     r6, r6, r4
        mov     r3, lr
        add     r3, r3, #1
        mov     r1, r3
        mov     r2, #0
        mul     r0, r1, r6
        mul     r3, r5, r2
        add     r0, r0, r3
        umull   r3, r4, r5, r1
        add     r0, r0, r4
        mov     r4, r0
        mov     r2, r3, lsr #29
        mov     sl, r4, asl #3
        orr     sl, r2, sl
        mov     r9, r3, asl #3
        mov     r3, ip
        mov     r1, r3
        mov     r2, #0
        mov     r3, #1
        mov     r4, #0
        mov     r5, r1
        mov     r6, r2
        adds    r5, r5, r3
        adc     r6, r6, r4
        mov     r3, lr
        add     r3, r3, #1
        mov     r1, r3
        mov     r2, #0
        mul     r0, r1, r6
        mul     r3, r5, r2
        add     r0, r0, r3
        umull   r3, r4, r5, r1
        add     r0, r0, r4
        mov     r4, r0
        mov     r2, r3, lsr #29
        mov     r8, r4, asl #3
        orr     r8, r2, r8
        mov     r7, r3, asl #3
        mov     r3, ip
        add     r3, r3, #1
        mov     r2, lr
        add     r2, r2, #1
        mul     r3, r2, r3
        add     r3, r3, #7
        add     r3, r3, #7
        mov     r3, r3, lsr #3
        mov     r3, r3, asl #3
        sub     sp, sp, r3
        mov     r3, sp
        add     r3, r3, #7
        mov     r3, r3, lsr #3
        mov     r3, r3, asl #3
        str     r3, [fp, #-80]
        ldr     r2, [fp, #-80]
        mov     r3, ip
        add     r3, r3, #1
        mov     r1, lr
        add     r1, r1, #1
        mul     r3, r1, r3
        mov     r0, r2
        mov     r1, #32
        mov     r2, r3
        bl      memset
        mov     r3, #0
        str     r3, [fp, #-40]
        mov     r3, #0
        str     r3, [fp, #-44]
        b       .L20
.L24:
        mov     r3, #0
        str     r3, [fp, #-48]
        b       .L21
.L23:
        ldr     r2, [fp, #-40]
        ldr     r3, [fp, #-60]
        cmp     r2, r3
        bge     .L22
        ldr     r3, [fp, #-40]
        ldr     r0, [fp, #-96]
        mov     r1, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int)
        mov     r3, r0
        ldrb    r2, [r3, #0]    @ zero_extendqisi2
        ldr     r1, [fp, #-80]
        ldr     r3, [fp, #-44]
        ldr     r0, [fp, #-104]
        mul     r3, r0, r3
        add     r1, r1, r3
        ldr     r3, [fp, #-48]
        add     r3, r1, r3
        strb    r2, [r3, #0]
.L22:
        ldr     r3, [fp, #-40]
        add     r3, r3, #1
        str     r3, [fp, #-40]
        ldr     r3, [fp, #-48]
        add     r3, r3, #1
        str     r3, [fp, #-48]
.L21:
        ldr     r2, [fp, #-48]
        ldr     r3, [fp, #-68]
        cmp     r2, r3
        movge   r3, #0
        movlt   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        bne     .L23
        ldr     r3, [fp, #-44]
        add     r3, r3, #1
        str     r3, [fp, #-44]
.L20:
        ldr     r2, [fp, #-44]
        ldr     r3, [fp, #-64]
        cmp     r2, r3
        movge   r3, #0
        movlt   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        bne     .L24
        mov     r3, #0
        str     r3, [fp, #-52]
        b       .L25
.L28:
        mov     r3, #0
        str     r3, [fp, #-56]
        b       .L26
.L27:
        ldr     r4, [fp, #-108]
        ldr     r2, [fp, #-108]
        ldr     r1, [fp, #-80]
        ldr     r3, [fp, #-56]
        ldr     r0, [fp, #-104]
        mul     r3, r0, r3
        add     r1, r1, r3
        ldr     r3, [fp, #-52]
        add     r3, r1, r3
        ldrb    r3, [r3, #0]    @ zero_extendqisi2
        sub     r1, fp, #84
        mov     r0, r1
        mov     r1, r2
        mov     r2, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)
        sub     r3, fp, #84
        mov     r0, r4
        mov     r1, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
        sub     r3, fp, #84
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        ldr     r3, [fp, #-56]
        add     r3, r3, #1
        str     r3, [fp, #-56]
.L26:
        ldr     r2, [fp, #-56]
        ldr     r3, [fp, #-64]
        cmp     r2, r3
        movge   r3, #0
        movlt   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        bne     .L27
        ldr     r3, [fp, #-52]
        add     r3, r3, #1
        str     r3, [fp, #-52]
.L25:
        ldr     r2, [fp, #-52]
        ldr     r3, [fp, #-68]
        cmp     r2, r3
        movge   r3, #0
        movlt   r3, #1
        and     r3, r3, #255
        cmp     r3, #0
        bne     .L28
        ldr     sp, [fp, #-100]
        ldr     r0, [fp, #-108]
        ldr     r0, [fp, #-108]
        sub     sp, fp, #32
        ldmfd   sp!, {r4, r5, r6, r7, r8, r9, sl, fp, pc}
        sub     r3, fp, #84
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L30
.L30:
        ldr     r3, [fp, #-108]
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L31
.L31:
        ldr     sp, [fp, #-100]
        bl      __cxa_end_cleanup
.LC0:
        .ascii  "\000"
main:
        stmfd   sp!, {r4, fp, lr}
        add     fp, sp, #8
        sub     sp, sp, #36
        sub     r3, fp, #32
        mov     r0, r3
        bl      std::allocator<char>::allocator() [complete object constructor]
        sub     r2, fp, #36
        sub     r3, fp, #32
        mov     r0, r2
        ldr     r1, .L52
        mov     r2, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) [complete object constructor]
        sub     r3, fp, #32
        mov     r0, r3
        bl      std::allocator<char>::~allocator() [complete object destructor]
        sub     r3, fp, #40
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor]
        sub     r3, fp, #44
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor]
        sub     r2, fp, #24
        sub     r3, fp, #36
        mov     r0, r2
        mov     r1, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [complete object constructor]
        sub     r2, fp, #28
        sub     r3, fp, #24
        mov     r0, r2
        mov     r1, r3
        bl      encryption(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
        sub     r2, fp, #40
        sub     r3, fp, #28
        mov     r0, r2
        mov     r1, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
        sub     r3, fp, #28
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        sub     r3, fp, #24
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        sub     r3, fp, #40
        ldr     r0, .L52+4
        mov     r1, r3
        bl      std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
        mov     r3, r0
        mov     r0, r3
        ldr     r1, .L52+8
        bl      std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
        sub     r2, fp, #16
        sub     r3, fp, #40
        mov     r0, r2
        mov     r1, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [complete object constructor]
        sub     r2, fp, #20
        sub     r3, fp, #16
        mov     r0, r2
        mov     r1, r3
        bl      decryption(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
        sub     r2, fp, #44
        sub     r3, fp, #20
        mov     r0, r2
        mov     r1, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
        sub     r3, fp, #20
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        sub     r3, fp, #16
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        sub     r3, fp, #44
        ldr     r0, .L52+4
        mov     r1, r3
        bl      std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
        mov     r4, #0
        sub     r3, fp, #44
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        sub     r3, fp, #40
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        sub     r3, fp, #36
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        mov     r3, r4
        mov     r0, r3
        sub     sp, fp, #8
        ldmfd   sp!, {r4, fp, pc}
        sub     r3, fp, #32
        mov     r0, r3
        bl      std::allocator<char>::~allocator() [complete object destructor]
        bl      __cxa_end_cleanup
        sub     r3, fp, #28
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L38
.L38:
        sub     r3, fp, #24
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L39
        sub     r3, fp, #20
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L41
.L41:
        sub     r3, fp, #16
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L39
.L39:
        sub     r3, fp, #44
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L42
.L42:
        sub     r3, fp, #40
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        b       .L43
.L43:
        sub     r3, fp, #36
        mov     r0, r3
        bl      std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
        bl      __cxa_end_cleanup
.L52:
        .word   .LC0
        .word   _ZSt4cout
        .word   _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
__static_initialization_and_destruction_0(int, int):
        stmfd   sp!, {fp, lr}
        add     fp, sp, #4
        sub     sp, sp, #8
        str     r0, [fp, #-8]
        str     r1, [fp, #-12]
        ldr     r3, [fp, #-8]
        cmp     r3, #1
        bne     .L62
        ldr     r2, [fp, #-12]
        ldr     r3, .L64
        cmp     r2, r3
        bne     .L62
        ldr     r0, .L64+4
        bl      std::ios_base::Init::Init() [complete object constructor]
        ldr     r3, .L64+8
        ldr     r0, .L64+4
        mov     r1, r3
        ldr     r2, .L64+12
        bl      __aeabi_atexit
.L62:
        sub     sp, fp, #4
        ldmfd   sp!, {fp, pc}
.L64:
        .word   65535
        .word   _ZStL8__ioinit
        .word   _ZNSt8ios_base4InitD1Ev
        .word   __dso_handle
global constructors keyed to encryption(std::basic_string<char, std::char_traits<char>, std::allocator<char> >):
        stmfd   sp!, {fp, lr}
        add     fp, sp, #4
        mov     r0, #1
        ldr     r1, .L67
        bl      __static_initialization_and_destruction_0(int, int)
        ldmfd   sp!, {fp, pc}
.L67:
        .word   65535
Posted
Updated 11-Jul-22 12:52pm
Comments
merano99 11-Jun-21 18:57pm    
You are asking for a solution for Arm assembler but you also propose various Intel assembler solutions. The difference is obvious, but it doesn't seem clear to you. A little more preparatory work would be necessary here.
Solution one, three and four even seem to come from the DOS era, that was a long time ago and makes little sense here ...

Why this was marked with C and C ++ here is also not clear to me.
Hamza Abd 11-Jun-21 19:56pm    
I am sorry for my bad question .. but I really don't know where or how to ask
since I have to solve this question but I don't know anything about the language because they just teach us theory classes and I don't have time to study it ...
I understand from you that the first sol. right ?
is it in arm ?
please try to explain the question to me and how I should solve it

To be honest the second code was c code and I converted it to arm assembly by using tool also the fourth sol. was c++ ...
jeron1 11-Jun-21 20:54pm    
"and I don't have time to study it..."

Well there's your problem.
Hamza Abd 11-Jun-21 19:57pm    
I hope you help me as possible as you can
Dave Kreskowiak 11-Jun-21 23:57pm    
Help you? How?

You seem to want someone to write the code for you and that's not going to happen.

There is no solution anyone can give you for "I don't have time to study it ..."

Quote:
I am sorry for my bad question .. but I really don't know where or how to ask
since I have to solve this question but I don't know anything about the language because they just teach us theory classes and I don't have time to study it ...

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you don't understand the assignment as set, you should discuss that with your tutor.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
first sol :
- This is x86 assembler, known as "mov ax,data".
(Probably from the DOS days, which you can see from "int 0x21".)

second sol :
- This is the ARM instruction set, as you can see from "mov r0, r3".

third sol and 4th sol :
- This is also old DOS x86 Assembler as you see from "INT 21H".

other sol :
- I think this is ARM assembler recognizable by "mov r3, r0"

If you have no idea what the solution looks like in assembler, you can also solve the problem in C and let the C compiler generate the assembler code.

Note that ARM cores support both big and little endian modes.
 
Share this answer
 
v2
Comments
Dave Kreskowiak 11-Jul-22 20:35pm    
Check the date on the question. It's a year old.
merano99 11-Jul-22 21:11pm    
Since the author has revised his question, he seems to be still looking for an answer.
Dave Kreskowiak 11-Jul-22 21:13pm    
Either way, it's a homework assignment.

He cannot use C to generate the ASM code. It'll be obvious he didn't write it as required.
Richard Deeming 12-Jul-22 4:19am    
The author hasn't updated his question; someone posted a new solution to the question (solution 1), which has since been deleted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900