In: Computer Science
We can allocate string literals and global variables
in the .data section of an assembly language program.
Write MARS directives which would allocate the following C-like
variables in the .data section.
char ch1 = ' ', ch2 = '$';
// Assume char variables/values are 1-byte
int x = 0, y = -1, z;
// Assume int variables/values are 4-bytes
char *name = "Marge Simpson";
// name is a label assoc'd with the address of the first char
int iarray[250] = { 0 };
// iarray is an array of 250 ints, all initialized to 0
char carray[250] = { 0 };
// carray is an array of 250 chars, all initialized to 0
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.globl ch1
.data
.type ch1, @object
.size ch1, 1
ch1:
.byte 32
.globl ch2
.type ch2, @object
.size ch2, 1
ch2:
.byte 42
b)
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.globl x
.section .bss,"aw",@nobits
.align 2
.type x, @object
.size x, 4
x:
.space 4
.globl y
.data
.align 2
.type y, @object
.size y, 4
y:
.word -1
.globl z
.section .bss
.align 2
.type z, @object
.size z, 4
z:
.space 4
(c)
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.globl name
.rdata
.align 2
$LC0:
.ascii "marge simpson\000"
.section .data.rel.local,"aw",@progbits
.align 2
.type name, @object
.size name, 4
name:
.word $LC0
(d)
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.globl arrayi
.section .bss,"aw",@nobits
.align 2
.type arrayi, @object
.size arrayi, 1000
arrayi:
.space 1000
(e)
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.globl arrayi
.section .bss,"aw",@nobits
.align 2
.type arrayi, @object
.size arrayi, 1000
arrayi:
.space 1000