03.Lab02-2.LC-2K Assembly-Language Programming
更新时间:2023-12-01 08:26:01 阅读量: 教育文库 文档下载
Laboratory2-2 Programming
LC-2KAssembly-Language
Laboratory2.2.1 Multiplication
1. Purpose
This project is intended to help you understand the instructions of a verysimple assembly language and how to write simple assembly language program.
2. Problem
In thislab, you will write a shortassembly-language program to multiply two numbers.
3. Assembly-Language Multiplication
This assignment is to write an assembly-language program tomultiply two numbers. Input the numbers by reading memory locations called\and \result should be stored in register 1 when theprogram halts. You may assume that the two input numbers are at most 15 bitsand are positive; this ensures that the (positive) result fits in an LC-2Kword. See the algorithm on page 178 of the textbook (3rd edition) or page232 of the textbook (4th edition) for an idea of how to multiply.
Remember that shifting left by one bit is the same as adding the number toitself. Given the LC-2K instruction set, it's easiest to modify thealgorithm so that you avoid the right shift. Submit a version of the programthat computes (32766 * 10383).
Your multiplication program must be reasonably efficient--it must be at most50 lines long and execute at most 1000 instructions for any valid input (thisis several times longer and slower than the solution). To achieve this, youmust use a loop and shift algorithm to perform the multiplication;
algorithmssuch as successive addition (e.g. multiplying 5 * 6 by adding 5 six times)will take too long.
4. Formatting
You must be careful to follow theexact formatting rules:
1) Store the result in register 1.
2) The two input numbers must be in locations labeled \
Laboratory2.2.2 Combination
1. Purpose
This project is intended to help you understand how procedure calls workin assembly language for a simple computer.
2. Problem
In this lab, you will write anassembly-language program to recursively compute combination(n,r)(i.e. n choose r).
3. Assembly-Language Program to Compute
Combination(n,r)
Write an assembly-language program to recursively computecombination(n,r), defined as:
combination(n,0) = 1 combination(n,n) = 1
combination(n,r) = combination(n-1,r) + combination(n-1,r-1);
0 <= r <= n
Here's a C function to do this; your assembly-language program will followthis logic closely.
int combination(int n, int r) {
if (r==0 || n==r) { return(1); } else {
return(combination(n-1,r) + combination(n-1,r-1)); } }
Note that the definition of combination(n,r) is recursive.
Yourassembly-language program must also use a recursive function call.
That is,your program should have a function that calls itself twice (to computecombination(n-1,r) and combination(n-1,r-1)) and adds the results together.This isn't the most efficient solution (e.g. n>9 will take a LONG time), butusing recursion will help you understand assembly-language procedure calls andstacks. Your program should input the value n and r from memory locationslabeled \in register 3 when theprogram halts. Straightforward solutions are possible in about 45 lines. Ifyour program is significantly longer than that, you are probably doingsomething wrong. Your program must be reasonably efficient, i.e. it mustexecute at most 5000 instructions for n=7, r=3 (this is several times slowerthan a good solution).
Passing parameters to subroutines can be confusing in assembly language.It's easiest if you make most registers callee-save so the caller can assumethe subroutine leaves those registers unchanged. These
callee-saved registersare typically pushed on the stack at the beginning of the subroutine and poppedoff the stack just before the subroutine returns.
Not all registers can or should be callee-save, however. For example, oneregister will contain the subroutine's return value. Also, the jalr instructionused to return from the subroutine will leave a register with a differentvalue than it held when the subroutine was called.
Here is a small LC-2K program that uses a subroutine call. It takesan input and calls a subroutine to compute the quantity 4*input.
Register 1 is used to pass input to the subroutine; register 3 is used bythe subroutine to pass the result back. The current top-of-stack (firstempty location) is given by stack + register 7.
lw 0 5 pos1 $5 = 1
lw 0 1 input $1 = memory[input] lw 0 2 subAdr prepare to call sub4n. $2=sub4n jalr 2 4 call sub4n; $4=return address; $3=answer halt
sub4n sw 7 4 stack save return address on stack add 7 5 7 increment stack pointer sw 7 1 stack save $1 on stack
add 7 5 7 increment stack pointer add 1 1 1 compute 2*input add 1 1 3 compute 4*input lw 0 2 neg1 $2 = -1
add 7 2 7 decrement stack pointer
正在阅读:
03.Lab02-2.LC-2K Assembly-Language Programming12-01
小学生二年级五一郊游作文06-13
汽车尾灯控制电路doc - 图文03-09
石油化工装置自控仪表专业监理实务06-28
第五章 管理沟通与冲突01-09
数字PID控制算法仿真研究04-13
企业电子商务经营策略分析04-01
2018年中考数学精品资料全国初中数学竞赛辅导-平行四边形03-08
数电第三次实验 - 图文03-02
- 12.How - to - use - body - language - in - the - classroom
- 2m7unit2using language
- 3Unit2 language point1
- 4(刘润清版) chapter 2 the sounds of language
- 5英语必修2 unit 5 Using language
- 6转K2、K6型转向架简介2
- 7必修5 Unit 2 The United Kingdom using language
- 8lab15 语义分析与中间代码生成2
- 9LC—2控制器使用说明书
- 10DE2 实验练习解答—lab 1(Digital Logic)(DE2)(Quartus II)
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- Programming
- Assembly
- Language
- Lab
- 03
- 02
- LC