Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please use MIPS assembly Code 1. String shuffle. Two strings a1 ···an and b1 ···

ID: 3669259 • Letter: P

Question

please use MIPS assembly Code

1. String shuffle. Two strings a1 ···an and b1 ···bn with the same length can be shuffled as a1b1 · · · anbn. Your program is to read two strings (with the same length) from the keyboard and print the shuffle out.

2. Transposition. A string with length k · m can be transposed as follows. First, we cut the string into k blocks, each of which is of length m. Then, we pick the first character from each block, pick the second character from each block, etc. The characters picked in this order form a string, called a (k, m)-transposition. For instance, let k = 3 and m = 2. For a given string abcdef, its transposition is acebdf. Your program is to read, from keyboard, k, m, and a string of length k · m, and then print its transposition out.

3. Two digit adder. Your program is going to read a string from keyboard, where the string is in the following format: XX+YY= where the XX and the YY are two-digit numbers. Your program is going to print out the sum (for instance, when the string is 13+31=, the output should be 44.). However, when the sum is bigger than 99, pls print out overflow instead.

Explanation / Answer

1. This program as been made on the consideration of the C language.Most of the syntax has ben hord from this language.Thus some of the expression will look wierd but this will work just fine.

.Ltext0:
        .section   .rodata
    .LC0:
               .string   "Enter the first string"
               .LC1:
               .string   "Enter the second string"
              
               .LC2:
               .string   "%s %s"
               .text
        .globl   main
    main:
    .LFB0:
        .cfi_startproc
                   pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
                   movq   %rsp, %rbp
        .cfi_def_cfa_register 6
                   subq   $240, %rsp
                   movq   %fs:40, %rax
                   movq   %rax, -8(%rbp)
                   xorl   %eax, %eax
                   movl   $0, -232(%rbp)
                   movl   $0, -228(%rbp)
                   movl   $0, -240(%rbp)
                   movl   $0, -236(%rbp)
                   movl   $.LC0, %edi
                   movl   $0, %eax
                   call   printf
                   leaq   -224(%rbp), %rax
                   movq   %rax, %rdi
                   call   gets
                   movl   $.LC1, %edi
                   movl   $0, %eax
                   call   printf
                   leaq   -112(%rbp), %rax
                   movq   %rax, %rdi
                   call   gets
                   leaq   -224(%rbp), %rax
                   movq   %rax, %rdi
                   call   strlen
                   movl   %eax, -232(%rbp)
                   leaq   -112(%rbp), %rax
       movq   %rax, %rdi
                   call   strlen
                    movl   %eax, -228(%rbp)
                   movl   $0, -240(%rbp)
                    movl   $0, -236(%rbp)
                   jmp   .L2
                  
                   .L3:
                           addl   $1, -240(%rbp)
                            addl   $1, -236(%rbp)
                            movl   -236(%rbp), %eax
                           cltq
                           movzbl   -112(%rbp,%rax), %eax
                            movsbl   %al, %edx
                           movl   -240(%rbp), %eax
                           cltq
                           movzbl   -224(%rbp,%rax), %eax
                           movsbl   %al, %eax
                           movl   %eax, %esi
                           movl   $.LC2, %edi
                            movl   $0, %eax
                           call   printf
                          
                   .L2:
                           movl   -236(%rbp), %eax
                           cmpl   -228(%rbp), %eax
                            jl   .L3
                           movl   $0, %eax
                            movq   -8(%rbp), %rcx
                           xorq   %fs:40, %rcx
                            je   .L5
                       call   __stack_chk_fail
   .L5:
                           leave
                       .cfi_def_cfa 7, 8
                           ret
                       .cfi_endproc
    .LFE0:
    .Letext0:

3.To calculate the sum of the numbers which are passed as string, we need to split the string into the two parts and the be converted to the integers.The delimerter is "+" in this case on which both the string will be splitted and hence the resulted sum will be calculated.

.Ltext0:
.section  
               .rodata
    .LC0:
                   .string   "Input the string"
.LC1:
                   .string   "The sum is %d"
        .text
        .globl   main
    main:
    .LFB0:
        .cfi_startproc
                   pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
                   movq   %rsp, %rbp
        .cfi_def_cfa_register 6
                   subq   $144, %rsp
                   movq   %fs:40, %rax
                   movq   %rax, -8(%rbp)
                   xorl   %eax, %eax
                   movl   $0, -124(%rbp)
                    movl   $0, -128(%rbp)
                    movw   $43, -144(%rbp)
                   movl   $.LC0, %edi
                   movl   $0, %eax
                   call   printf
                   leaq   -112(%rbp), %rax
                   movq   %rax, %rdi
                   call   gets
                   leaq   -144(%rbp), %rdx
                   leaq   -112(%rbp), %rax
                   movq   %rdx, %rsi
                   movq   %rax, %rdi
                   call   strtok
                   movq   %rax, -120(%rbp)
                   jmp   .L2
               .L3:
    .LBB2:
                   movq   -120(%rbp), %rax
                   movq   %rax, %rdi
                   movl   $0, %eax
                    call   atoi
                   movl   %eax, -124(%rbp)
                   leaq   -144(%rbp), %rax
                   movq   %rax, %rsi
                   movl   $0, %edi
                   call   strtok
                   movq   %rax, -120(%rbp)
                   movl   -124(%rbp), %eax
                   addl   %eax, -128(%rbp)
    .L2:
    .LBE2:
                   cmpq   $0, -120(%rbp)
                   jne   .L3
                   movl   -128(%rbp), %eax
                   movl   %eax, %esi
                   movl   $.LC1, %edi
                   movl   $0, %eax
                   call   printf
                   movl   $0, %eax
                   movq   -8(%rbp), %rcx
                   xorq   %fs:40, %rcx
                   je   .L5
                   call   __stack_chk_fail
  
    .L5:
                   leave
        .cfi_def_cfa 7, 8
                   ret
        .cfi_endproc
    .LFE0:
    .Letext0: