NivaarExam PrepOfficial exam papers ↗

22-Elec-A4 Digital Systems and Computers · May 2015

Question 6 of 6: Big-endian storage and stack operation

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

Paper format. National Exams, May 2015 — 07-Elec-A4 Digital Systems & Computers. Three hours, closed book, one approved Casio or Sharp calculator. Six questions are printed and five constitute a complete exam; every question is worth 12 marks, with the per-part split printed in the marking scheme on page 1. A flip-flop excitation table and a Boolean-identity sheet are attached to the paper. All six questions are solved below, so that the set works as a complete study resource.

Reference texts.

Question 6 (12 marks) — Big-endian storage and stack operation

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given. A big-endian Motorola-style processor with byte-addressable memory; the 16-bit datum $\mathtt{10B2}_{16}$ to be stored at address $\mathtt{C109}_{16}$; the 16-bit datum $\mathtt{2EA4}_{16}$ to be pushed with the stack pointer holding $\mathtt{DFE8}_{16}$ before the push; and two three-byte memory windows, drawn with low memory at the top.

Find. (a) the byte contents of $\mathtt{C108}_{16}$–$\mathtt{C10A}_{16}$ after the store; (b) the byte contents of $\mathtt{DFE7}_{16}$–$\mathtt{DFE9}_{16}$ after the push; (c) the value of SP after the push.

Approach. Apply the big-endian rule — most significant byte at the lowest address — to the store, then apply the Motorola stack convention in which SP points at the next free byte and is post-decremented after each byte is written, taking care that the resulting pair of bytes must still read big-endian in memory.

  1. (a) Split the datum. $\mathtt{10B2}_{16}$ has high-order byte $\mathtt{10}_{16}$ and low-order byte $\mathtt{B2}_{16}$. Big-endian means the big end of the number goes to the first (lowest) address, so $\boxed{(\mathtt{C109}_{16})=\mathtt{10}_{16}\ \text{and}\ (\mathtt{C10A}_{16})=\mathtt{B2}_{16}}$. The instruction names $\mathtt{C109}_{16}$ as the operand address, and a 16-bit store occupies that address and the one above it; $\mathtt{C108}_{16}$ lies below the operand address and is therefore untouched. Its previous contents remain whatever they were.
STORE the 16-bit number 10B2 at address C109 (big-endian)1-byte locationsLow memoryC108unchangedC10910C10AB2High memoryThe high-order byte 10 occupies the lower address, C109.
Question 6(a) — result of the 16-bit store. The high-order byte takes the lower address.
  1. (b) Apply the Motorola push convention. On the 6800/68HC11 family the stack grows towards lower addresses and SP points at the next free byte, so each push writes at $(\text{SP})$ and then decrements SP. A 16-bit push writes the low-order byte first: $\mathtt{A4}_{16}\to\mathtt{DFE8}_{16}$, SP becomes $\mathtt{DFE7}_{16}$; then the high-order byte $\mathtt{2E}_{16}\to\mathtt{DFE7}_{16}$, SP becomes $\mathtt{DFE6}_{16}$. Hence $\boxed{(\mathtt{DFE7}_{16})=\mathtt{2E}_{16}\ \text{and}\ (\mathtt{DFE8}_{16})=\mathtt{A4}_{16}}$, with $\mathtt{DFE9}_{16}$ unchanged.
  2. Cross-check the byte order against part (a). The pair now in memory reads $\mathtt{2E}$ at the lower address and $\mathtt{A4}$ at the higher one, i.e. $\mathtt{2EA4}_{16}$ read big-endian — exactly the same convention as the store in part (a). This is the whole reason the low byte is pushed first on a downward-growing stack: writing the high byte first would leave the word stored little-endian and the matching PULL would return the bytes swapped.
PUSH the 16-bit number 2EA4 with SP = DFE8 before the push1-byte locationsLow memoryDFE72EDFE8A4DFE9unchangedHigh memorySP beforeLow byte first at DFE8, then high byte at DFE7; SP ends at DFE6.
Question 6(b) — result of the 16-bit push. Two bytes are written below and at the original SP; the word still reads big-endian in memory.
  1. (c) Final stack pointer. Two bytes were pushed and SP is decremented once per byte, so $$\text{SP}_{\text{after}}=\mathtt{DFE8}_{16}-2=\boxed{\mathtt{DFE6}_{16}}$$ which again points at the next free byte, one location below the high-order byte just written.
Question 6 — final results
LocationContents after execution
$\mathtt{C108}_{16}$unchanged (below the operand address)
$\mathtt{C109}_{16}$$\mathtt{10}_{16}$ (high-order byte)
$\mathtt{C10A}_{16}$$\mathtt{B2}_{16}$ (low-order byte)
$\mathtt{DFE7}_{16}$$\mathtt{2E}_{16}$ (high-order byte)
$\mathtt{DFE8}_{16}$$\mathtt{A4}_{16}$ (low-order byte)
$\mathtt{DFE9}_{16}$unchanged
SP after PUSH$\mathtt{DFE6}_{16}$
Back to the paper →