0%

ICS lab 1:Counting how many 1

本文用于记录计算系统概论第一次实验的步骤与过程。

Basic Information | 基本信息

  • Device: DELL
  • System: Kubuntu 22.04
  • Platform: LC-3 simulator
  • Language: assembler language

Steps | 操作步骤

Preparation

  • Download LC-3 Simulator from Web path: /home/Jeffrey/Downloads/ICS/lc3tools
  • Install modules: gcc, wish, flex
    1
    2
    3
    sudo apt install gcc
    sudo apt install wish
    sudo apt install flex
  • Open Makefile
    • find 'OS_SIM_LIBS = -lcurses'
    • delete '-lcurses'
  • cd Downloads/ICS/lc3tools
  • bash Compilation: make
  • bash instruction: ./lc3sim
    1
    2
    3
    4
    PC=x0494 IR=xB1AE PSR=x0400 (ZERO)
    R0=x0000 R1=x7FFF R2=x0000 R3=x0000 R4=x0000 R5=x0000 R6=x0000 R7=x0490
    x0494 x0FF9 BRNZP TRAP_HALT
    (lc3sim)

Tools & Functions

  • Start the simulator: ./lc3sim-tk
  • .asm to .obj & .sym: ./lc3as <filename>
  • .hex to .obj: ./lc3convert -b16 addnums.hex
  • .bin to .obj: ./lc3convert -b2 addnums.bin

Contents | 实验内容

Purpose

Write a program in LC-3 machine language, which counts how many 1 are in the lower B bits of a given number A. The output will be stored in memory.

Principles

R0 x3100 A

R1 x3101 B

R2 x3102 Output

R3 x3103 marker: mark whether the bit is 0 or 1

R4 x3104 pointer: point lower B bits