We can allocate string literals and global variables in the

. 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

Solution

Following are the MARS directives:

.data # This command tells the assembler that we are in the data segment

x: .word 0 # variable x is declared with initial value 0
y: .word -1,z
ch1: .byte \' \'
ch2: .byte \'$\'
iarray: .space 1000 0 # declare 1000 bytes of storage to hold an array of 250 integers initialized to 0
carray:   .space 500 0 #250 elements character array initialized to 0
name: .asciiz \"Marge Simpson\"
.text

. We can allocate string literals and global variables in the .data section of an assembly language program. Write MARS directives which would allocate the foll

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site