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

This problem gives a design with an if structure and some assumptions about how

ID: 3678613 • Letter: T

Question

This problem gives a design with an if structure and some assumptions about how the variables are stored in an assembly language program.

Give a fragment of 80x86 assembly code that implements the design. The assembly language code should flow the same as the design.

a) design:

Assume the character check is in AL

             If a + b = c

                then

                    check = 'Y';

                else

                    check = 'N'

               end if

b) design:
if (ch >= 'a') and (ch <= 'z')
   then
      add 1 to lowerCount;
    else
       if (ch >= 'A') and (ch <= 'Z')
          then
             add 1 to upperCount;
        else
            add 1 to otherCount;
        end if;
end if;
Assumptions: ch is in AL; each of lowerCount, upperCount, and other-Count references a doubleword in memory

Explanation / Answer

Answer:

a) Assembly Language Code:

.Ltext0:
        .local   _ZStL8__ioinit
        .comm   _ZStL8__ioinit,1,1
        .globl   main
    main:
    .LFB971:
        .cfi_startproc
0000 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0001 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6
    .LBB2:
0004 8B45F8        movl   -8(%rbp), %eax
0007 8B55F4        movl   -12(%rbp), %edx
000a 01D0        addl   %edx, %eax
000c 3B45FC        cmpl   -4(%rbp), %eax
000f 7506        jne   .L2
0011 C645F359        movb   $89, -13(%rbp)
0015 EB04        jmp   .L3
    .L2:
0017 C645F34E        movb   $78, -13(%rbp)
    .L3:
    .LBE2:
001b B8000000        movl   $0, %eax

0020 5D        popq   %rbp
        .cfi_def_cfa 7, 8
0021 C3        ret
        .cfi_endproc
    .LFE971:
    _Z41__static_initialization_and_destruction_0ii:
    .LFB972:
003f BF000000        movl   $_ZStL8__ioinit, %edi

0044 E8000000        call   _ZNSt8ios_base4InitC1Ev

0049 BA000000        movl   $__dso_handle, %edx

004e BE000000        movl   $_ZStL8__ioinit, %esi

0053 BF000000        movl   $_ZNSt8ios_base4InitD1Ev, %edi

0058 E8000000        call   __cxa_atexit

        .cfi_startproc
0022 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0023 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6
0026 4883EC10        subq   $16, %rsp
002a 897DFC        movl   %edi, -4(%rbp)
002d 8975F8        movl   %esi, -8(%rbp)
0030 837DFC01        cmpl   $1, -4(%rbp)
0034 7527        jne   .L5
0036 817DF8FF        cmpl   $65535, -8(%rbp)

003d 751E        jne   .L5
    .L5:
005d C9        leave
        .cfi_def_cfa 7, 8
005e C3        ret
        .cfi_endproc
    .LFE972:
    _GLOBAL__sub_I_main:
    .LFB973:
        .cfi_startproc
005f 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0060 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6
0063 BEFFFF00        movl   $65535, %esi

0068 BF010000        movl   $1, %edi

006d E8B0FFFF        call   _Z41__static_initialization_and_destruction_0ii

0072 5D        popq   %rbp
        .cfi_def_cfa 7, 8
0073 C3        ret
        .cfi_endproc
    .LFE973:
        .section   .init_array,"aw"
        .align 8
0000 00000000        .quad   _GLOBAL__sub_I_main

        .text
    .Letext0:

b) Assembly Language Code:

.Ltext0:
        .local   _ZStL8__ioinit
        .comm   _ZStL8__ioinit,1,1
        .globl   main
    main:
    .LFB971:
        .cfi_startproc
0000 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0001 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6
    .LBB2:
0004 C745F400        movl   $0, -12(%rbp)

000b C745F800        movl   $0, -8(%rbp)
  
0012 C745FC00        movl   $0, -4(%rbp)
  
0019 807DF360        cmpb   $96, -13(%rbp)
001d 7E0C        jle   .L2
001f 807DF37A        cmpb   $122, -13(%rbp)
0023 7F06        jg   .L2
0025 8345F401        addl   $1, -12(%rbp)
0029 EB16        jmp   .L3
    .L2:
002b 807DF340        cmpb   $64, -13(%rbp)
002f 7E0C        jle   .L4
0031 807DF35A        cmpb   $90, -13(%rbp)
0035 7F06        jg   .L4
0037 8345F801        addl   $1, -8(%rbp)
003b EB04        jmp   .L3
    .L4:
003d 8345FC01        addl   $1, -4(%rbp)
    .L3:
    .LBE2:
0041 B8000000        movl   $0, %eax

0046 5D        popq   %rbp
        .cfi_def_cfa 7, 8
0047 C3        ret
        .cfi_endproc
    .LFE971:
    _Z41__static_initialization_and_destruction_0ii:
    .LFB972:
0065 BF000000        movl   $_ZStL8__ioinit, %edi

006a E8000000        call   _ZNSt8ios_base4InitC1Ev

006f BA000000        movl   $__dso_handle, %edx

0074 BE000000        movl   $_ZStL8__ioinit, %esi

0079 BF000000        movl   $_ZNSt8ios_base4InitD1Ev, %edi

007e E8000000        call   __cxa_atexit

        .cfi_startproc
0048 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0049 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6
004c 4883EC10        subq   $16, %rsp
0050 897DFC        movl   %edi, -4(%rbp)
0053 8975F8        movl   %esi, -8(%rbp)
0056 837DFC01        cmpl   $1, -4(%rbp)
005a 7527        jne   .L6
005c 817DF8FF        cmpl   $65535, -8(%rbp)

0063 751E        jne   .L6
    .L6:
0083 C9        leave
        .cfi_def_cfa 7, 8
0084 C3        ret
        .cfi_endproc
    .LFE972:
    _GLOBAL__sub_I_main:
    .LFB973:
        .cfi_startproc
0085 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0086 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6
0089 BEFFFF00        movl   $65535, %esi
  
008e BF010000        movl   $1, %edi

0093 E8B0FFFF        call   _Z41__static_initialization_and_destruction_0ii

0098 5D        popq   %rbp
        .cfi_def_cfa 7, 8
0099 C3        ret
        .cfi_endproc
    .LFE973:
        .section   .init_array,"aw"
        .align 8
0000 00000000        .quad   _GLOBAL__sub_I_main
        .text
    .Letext0:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote