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

Assembly Language Problem Help: I already finished problem 1 but I really need h

ID: 3919990 • Letter: A

Question

Assembly Language Problem Help:

I already finished problem 1 but I really need help with problems 2 & 3:

printAlpha.s:

.intel_syntax noprefix
.data
n1:
.int 97
n2:
.int 122

.text
.globl main

main: mov ebx, DWORD PTR n1
loop: cmp ebx, DWORD PTR n2
jg end
      mov edi, ebx
      call putchar
      inc ebx
      jmp loop
end:      mov edi, 10
      call putchar
      mov eax, 0
      ret

OR, here is a picture of printAlpha.s:

.intel_syntax noprefix
.data
n1:
.int 97
n2:
.int 122

.text
.globl main

main: mov ebx, DWORD PTR n1
loop: cmp ebx, DWORD PTR n2
jg end
      mov edi, ebx
      call putchar
      inc ebx
      jmp loop
end:      mov edi, 10
      call putchar
      mov eax, 0
      ret

After successfully logging into Highlander AFS using SSH client such as MobaXterm, assemble, link, and run the "printAlpha.s" assembly language program using the following steps: 1. as printAlpha.s -o printAlpha.o 2. gcc printAlpha.o 3. ./a.out The program prints the alphabetical characters from a' to 'z' on one line as follows: $./a.out abcdefghijklmnopqrstuvwxyz Make 2 copies of the printAlpha.s file, and call them mountainTerrain.s, and triangle.s Problem 1 Annotate the printAlpha.s file with line comments describing your understanding of what each line does. For example, line 19 should be annotated as follows call putchar # Call the C standard library function putchar(int) Problem 2 Edit the mountainTerrain.s file and change the code to alternate between upper and lower case characters while printing the alphabet. The output should be as follows: $ ./a.out AbCdEfGhIjKIMnOpQrStUvwxYz Problem 3 Edit the triangle.s file and change the code to print a triangle using lower case characters. The output should be as follows: . /a. out abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxy abcdefghijklmnopqrstuvwx abcdefghijklmnopqrstuvw abcdefghijklmnopqrstuv abcdefghijklmnopqrstu abcdefghijklmnopqrst abcdefghijklmnopqrs abcdefghijklmnopqr abcdefghijklmnopq abcdefghijklmnop abcdefghijklmno abcdefghij k1mn abcdefghijklm abcdefghijkl abcdefghijk abcdefghij abcdefghi abcdefgh abcdefg abcdef abcde abcd abc ab

Explanation / Answer

Problem 1)

.intel_syntax noprefix
.data
n1: .int 97                    # initialize n1=97
n2: .int 122                  # initialize n2=122

.text
.globl main

main: mov ebx, DWORD PTR n1      # move value of n1 into register ebx
loop: cmp ebx, DWORD PTR n2       # check if ebx>n2
jg end                                                  # if yes then jump to end
      mov edi, ebx                                 # if no then move ebx into edi
      call putchar                                    # call C lib func putchar to print value in edi copied above
      inc ebx                                           # increment ebx by 1
      jmp loop                                        # loop again
end:      mov edi, 10                            # move 10 into edi
      call putchar                                    #call C lib func
      mov eax, 0                                     # reset eax to 0
      ret                                                  # return from main

Problem 2)

Solution 1: Use conditional branch to output alternatively upper and lower case letters.

.intel_syntax noprefix

.data

n1:

.int 97

n2:

.int 122

.text

.globl main

main:

mov ebx, DWORD PTR n1

loop:

cmp ebx, DWORD PTR n2

jg end

cmp ebx, 97

jge ucase

add ebx, 32

mov edi, ebx

call putchar

inc ebx

jmp loop

ucase:

sub ebx, 32

mov edi, ebx

call putchar

inc ebx

jmp loop

end: mov edi, 10

call putchar

mov eax, 0

ret

Solution 2: You can use another variable as flag whose value will toggle between 0 or 1. Consider when this flag is 0 then print uppercase letter or if 1 then print lowercase letters. Initialize the flag as 0.

.intel_syntax noprefix

.data

n1:

.int 97

n2:

.int 122

.text

.globl main

main:

mov ebx, DWORD PTR n1

mov     ecx, 0

loop:

cmp ebx, DWORD PTR n2

jg end

cmp ecx, 0

je ucase

add ebx, 32

mov edi, ebx

call putchar

inc ebx

mov     ecx, 0

jmp loop

ucase:

sub ebx, 32

mov edi, ebx

call putchar

inc ebx

mov     ecx, 1

jmp loop

end: mov edi, 10

call putchar

mov eax, 0

ret

Problem 3) Create two loops, outer loop will execute 26 time to print the series and inner loop will execute edx-ecx times so as ecx increases number of times inner loop executes decreases.

.intel_syntax noprefix
.data
n1:
.int 97
n2:
.int 122

.text
.globl main

main: mov       ecx, 0

mov     edx, 26

LOOP:

cmp     ecx, 26

bge      end

mov ebx, DWORD PTR n1
sub      edx, edx, ecx

LOOP2:

cmp edx, 0
jle INCR

mov edi, ebx
call putchar
inc ebx

dec      edx
jmp LOOP2

INCR:

inc       ecx

jmp     LOOP


end:      mov edi, 10
      call putchar
      mov eax, 0
      ret

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