Published by Patrick Mutisya · 14 days ago
Demonstrate an understanding of how assembly language instructions are organised into logical groups (segments, blocks, and sub‑routines) to improve readability, maintainability and execution flow.
.data
msg: .asciiz "Enter a number: "
.text
.globl main
main:
# code here
| Group | Purpose | Typical Mnemonics |
|---|---|---|
| Data Transfer | Move data between registers, memory and I/O | LD, ST, MOV, LDR, STR |
| Arithmetic | Perform integer or floating‑point calculations | ADD, SUB, MUL, DIV |
| Logical | Bitwise manipulation and condition testing | AND, OR, XOR, NOT, CMP |
| Control Flow | Change the sequential execution order | JMP, CALL, RET, BEQ, BNE |
| System | Interact with the operating system or hardware | INT, S \cdot C, HLT |
; ---------- Data Segment ----------
.data
count: .word 0 ; variable to hold the counter
msg: .asciiz "Count = "
; ---------- Text Segment ----------
.text
.globl main
main:
; Initialise counter
LI R1, 0 ; R1 = 0
ST R1, count
loop_start:
; Increment counter
LD R2, count
ADDI R2, R2, 1
ST R2, count
; Print current value (calls sub‑routine)
CALL print_counter
; Loop 5 times
CMP R2, #5
BLT loop_start
; Exit program
MO \cdot R7, #1 ; syscall: exit
SWI 0
; ---------- Sub‑routine ----------
print_counter:
; Load message address
LDR R0, =msg
; Load current count
LD R1, count
; System call to write (pseudo‑code)
MO \cdot R7, #4
SWI 0
BX LR ; return
Write a short assembly program for a hypothetical processor that:
Explain how you have grouped the instructions and why the grouping aids understanding.