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

Hello. This is for another assignment in my Assemenbly Language class. Im using

ID: 645577 • Letter: H

Question

Hello. This is for another assignment in my Assemenbly Language class. Im using the book Assembly Language for x86 Processors, 7th ed, Irvine.

Your help is deeply appreciated once again. Thank you!

(1) Create a masm program, LP1A to prompt the user to enter a number
between 1 and 9. Write a nested loop to print the numbers as follows:
For e.g. if the user entered 9, then the output would be:

Enter a value for length: 9
123456789
12345678
1234567
123456
12345
1234
123
12
1

(2) Create masm program, LP1B to prompt the user to enter a number between 1 and 9. Write a nested loop to print the numbers as follows:
For e.g. if the user entered 9, then the output would be:

Enter a value for length: 9
1
12
123
1234
12345
123456
1234567
12345678
123456789

You must create a procedure that prompts the user for input. You must create a procedure to output the numbers as required. How are any arguments passed to the procedures?
.

(3) Create masm program, LP1C to prompt the user to enter a number between 1 and 9. Write a nested loop to print the numbers as follows:
For e.g. if the user entered 9, then the output would be:


Enter a value for length: 9
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999

You must create a procedure that prompts the user for input. You must create a procedure to output the numbers as required. Use a different method to pass arguments from (2) to the procedures?

Explanation / Answer

global _start

section .data
str: db 1

section .bss
e1_len resd 1
dummy resd 1

section .text

_start:
mov eax, 3 ; Read user input into str
mov ebx, 0 ; |
mov ecx, str ; | <- destination
mov edx, 1 ; | <- length
int 80h ;

mov [e1_len],eax ; Store number of inputted bytes
cmp eax, edx ; all bytes read?
jb .2 ; yes: ok
mov bl,[ecx+eax-1] ; BL = last byte in buffer
cmp bl,10 ; LF in buffer?
je .2 ; yes: ok
inc DWORD [e1_len] ; no: length++ (include 'lf')

.1: ; Loop
mov eax,3 ; SYS_READ
mov ebx, 0 ; EBX=0: STDIN
mov ecx, dummy ; pointer to a temporary buffer
mov edx, 1 ; read one byte
int 0x80 ; syscall
test eax, eax ; EOF?
jz .2 ; yes: ok
mov al,[dummy] ; AL = character
cmp al, 10 ; character = LF ?
jne .1 ; no -> next character
.2: ; end of loop

mov eax, 4 ; Print
mov ebx, 1 ; |
.4:
mov ecx, str ; | <- source
mov edx, [e1_len] ; | <- length
dec ecx
jz .3
jnz .4
int 80h ;

.3:
mov eax, 1 ; Return
mov ebx, 0 ; | <- return code
int 80h ;