VS 2017 (C/C++) / .386 architecture / Assembly language This is a practice with
ID: 3745008 • Letter: V
Question
VS 2017 (C/C++) / .386 architecture / Assembly language
This is a practice with symbolic constant definitions either using integers or strings. The requirement is as follows:
1. Write a program that defines symbolic constants for all seven days of the week
• Define each integer value for symbol Monday, ..., Sunday to simulate C++ enumeration type
• In the data segment, create an array to uses these symbols as initializers
• Use $ operator to calculate the number of elements in the array
• In the code segment, watch the array count with a register
2. Write a program that defines symbolic names for several string literals
• Define three strings for symbol named like Message1, Message2, etc.
• In the data segment, use each symbolic name to initialize the string variables
• Try to use 0D and 0A, as well as a zero terminator in your definitions
• In the code segment, set a break point and when running in debug, you can watch your string memory
Explanation / Answer
part1.asm
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
;Define each integer value for symbol Monday, ..., Sunday to simulate C++ enumeration type
Monday = 0
Tuesday = 1
Wednesday = 2
Thursday = 3
Friday = 4
Saturday = 5
Sunday = 6
.data
;In the data segment, create an array to uses these symbols as initializers
array DWORD Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
;Use $ operator to calculate the number of elements in the array
arraySize = ($ - array) / 4
.code
main1 proc
;In the code segment, watch the array count with a register
mov eax, arraySize
invoke ExitProcess,0
main1 endp
end main1
============================================================================
part2.asm
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
;Define three strings for symbol named like Message1, Message2, etc.
Message1 TEXTEQU <"Message1">
Message2 TEXTEQU <"Message2">
Message3 TEXTEQU <"Message3">
.data
;In the data segment, use each symbolic name to initialize the string variables
str1 BYTE Message1,0dh,0ah,0
str2 BYTE Message2,0dh,0ah,0
str3 BYTE Message3,0dh,0ah,0
.code
main1 proc
;no code needed, set a breakpoint here to watch the strings in memory
invoke ExitProcess,0
main1 endp
end main1
==============================================================================
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.