Question: Objectives: This exercise aims to demonstrate how Assembly code translates to the circuits, which is what you already learned reading about the IA32 architecture. Description:
Objectives: This exercise aims to demonstrate how Assembly code translates to the circuits, which is what you already learned reading about the IA32 architecture.
Description:
Below is the code that calculates the users age in dog years. Considering that the .data segment starts at the address 0x1000 in main memory, the .code segment start at the address 0x2000 in cache memory, and the value for the age the user gives is 20, write down the changes in variables and registers for each instruction. Assume that when the OFFSET operator in used, only the address of the variable is fetched, NOT the data. The first 4 instructions are given. You can stop after the instruction exit
EXTRA CREDIT (+10 points): Modify the code in Visual Studio so when the user enters a number for their age below 5, the program prints out a message Wow! That young, yet you know how to use a computer!.
What to submit: Both, the document file with the program execution and the .asm file for the extra credit.
TITLE Dog years (dog.asm)
; Description: This program gets the age of the user and calculates their age in dog years (age x 7).
INCLUDE Irvine32.inc
.data
age DWORD ? ; User's age
hi_there BYTE "Hi there, this is John",0 ; Greeting the user
prompt1 BYTE "Can I have your age please?",0 ; Gets age
output BYTE "So, your age in dog years is: ",0 ; Reposts dog age
byebye BYTE "Thanks for passing by, have a great day!",0 ; Bye bye
.code
main PROC
; Greet the user
mov EDX, OFFSET hi_there ; Set up for call to WriteString and greet the user
call WriteString
call Crlf
; Gets the user's age
mov EDX, OFFSET prompt1 ; Asks the user's age
call WriteString
call Crlf
call ReadInt ; Reads the users age. Age in EAX
call Crlf
; Calculate the dog years and stores the dog age
mov EBX, 7
mul EBX
mov age, EAX ; Stores the users dog age. Dog age also in EAX
; Reports the dog years and says bye
mov EDX, OFFSET output
call WriteString
mov EAX, age
call WriteDec
call Crlf
mov EDX, OFFSET byebye
call WriteString
call Crlf
exit ;exit to operating system
main ENDP
END main

*************************************************************************************************
in class demo

Address Instruction EIP EIR L EID MDR MAR LEAX EBX ECX EDX age main PROC main PROC main PROC . Ox2000 Ox2004 OX2004 Ox2008 0x1004 ? clo ? . mov EDX, OFFSET hi there call WriteString call Crif Ox2008 mov EDX, OFFSET hi there call WriteString call Crlf mov EDX, OFFSET hi_there call WriteString call Crif Ox1004 Ox1004 Ox200C Ox101A . 0X200C Ox2010 0 0x101A ? ? ? Ox1004 ; AddTwo. asm - adds two 32-bit integers. ; Chapter 3 example INCLUDE Irvine32.inc .386 .model flat, stocall .stack 4096 ;SS Exit Process proto, dwExitCode: dword .data into1 BYTE "Hi, this is Paris", prompt1 BYTE "Please give me your name.",0 prompt2 BYTE "Please give me your age.",0 Name BYTE 15 DUP (O) NameLength DWORD ? uAge DWORD ? uCreeti BYTE "Hi", uCreet2 BYTE " your age in dog's years is: ",0 dYears DWORD? bye1 BYTE "Thanks for playing! Have a nice day!", .code main proc Introduction: mov EDX, OFFSET into1 call WriteString call Crlf Get_name_age: MOV EDX, OFFSET prompt1 call writeString call Crif mov EDX, OFFSET UName mov ECX, 15 call ReadString movuNameLength, EAX call Crlf call writeDec call Crif mov EDX, OFFSET prompt2 call writeString call Crlf call ReadInt movuAge, EAX Calculate_dog_years: mov EAX, UAge mov EBX, 7 mul EBX mov dYears, EAX Report_dog_years: mov EDX, OFFSET uCreet1 call writeString mov EDX, OFFSET UName call WriteString mov EDX, OFFSET uCreet2 call WriteString mov EAX, dYears call writeDec call Crlf Good_bye: mov EDX, OFFSET bye1 call writeString call Crlf invoke Exit Process, main endp end main Address Instruction EIP EIR L EID MDR MAR LEAX EBX ECX EDX age main PROC main PROC main PROC . Ox2000 Ox2004 OX2004 Ox2008 0x1004 ? clo ? . mov EDX, OFFSET hi there call WriteString call Crif Ox2008 mov EDX, OFFSET hi there call WriteString call Crlf mov EDX, OFFSET hi_there call WriteString call Crif Ox1004 Ox1004 Ox200C Ox101A . 0X200C Ox2010 0 0x101A ? ? ? Ox1004 ; AddTwo. asm - adds two 32-bit integers. ; Chapter 3 example INCLUDE Irvine32.inc .386 .model flat, stocall .stack 4096 ;SS Exit Process proto, dwExitCode: dword .data into1 BYTE "Hi, this is Paris", prompt1 BYTE "Please give me your name.",0 prompt2 BYTE "Please give me your age.",0 Name BYTE 15 DUP (O) NameLength DWORD ? uAge DWORD ? uCreeti BYTE "Hi", uCreet2 BYTE " your age in dog's years is: ",0 dYears DWORD? bye1 BYTE "Thanks for playing! Have a nice day!", .code main proc Introduction: mov EDX, OFFSET into1 call WriteString call Crlf Get_name_age: MOV EDX, OFFSET prompt1 call writeString call Crif mov EDX, OFFSET UName mov ECX, 15 call ReadString movuNameLength, EAX call Crlf call writeDec call Crif mov EDX, OFFSET prompt2 call writeString call Crlf call ReadInt movuAge, EAX Calculate_dog_years: mov EAX, UAge mov EBX, 7 mul EBX mov dYears, EAX Report_dog_years: mov EDX, OFFSET uCreet1 call writeString mov EDX, OFFSET UName call WriteString mov EDX, OFFSET uCreet2 call WriteString mov EAX, dYears call writeDec call Crlf Good_bye: mov EDX, OFFSET bye1 call writeString call Crlf invoke Exit Process, main endp end main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
