Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Lab 6 -60-266 – use PUSH and POP operations to access stack

OBJECTIVES:
i) To learn about the runtime stack.
ii) To use PUSH and POP operations to access stack.

Problem: Read in your last name in lowercase letters (exclude any non-alphabetic characters). Store the name in a string. Reverse the string, convert each character to uppercase and display your name reversed and in uppercase.

Hints:

• Use ReadString to read in your name
• Use the stack for reversing the string.
• Convert to uppercase by subtracting 20h from each character.
• Use WrtieString to display the final string.

Answer:

INCLUDE Irvine32.inc

.data
prompt BYTE "Enter your last name in lowercase ",0
myName BYTE 50 DUP(0)
nameSize DWORD ?

.code
main PROC

	mov  edx,OFFSET prompt	
	call WriteString
	mov edx, OFFSET myName
	mov ecx, (SIZEOF myName) - 1
	call ReadString	
	mov nameSize, eax
	
	; Push the name on the stack.
	mov ecx,nameSize
	mov esi,0
	L1:	movzx eax,myName[esi]	; get character
		push eax	; push on stack
		inc esi
		Loop L1

	; Pop the name from the stack, in reverse,
	; convert to uppercase and store in the myName array.
		mov ecx,nameSize
		mov esi,0

	L2:	pop eax	; get character
		sub al, 20h
		mov myName[esi],al	; store in string
		inc esi
		Loop L2

	; Display the name.
		mov edx,OFFSET myName
		call Writestring
		call Crlf
		call DumpRegs
	exit
main ENDP
END main

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!