作者doubleday (......)
看板Grad-ProbAsk
標題Re: [理工] [計組]-高大98-資工系
時間Wed Jan 20 16:39:22 2010
※ 引述《tedmax100 (tedmax)》之銘言:
: Write a program using instructions in the instruction set shown below to
: output the result of A * B, where A and B are two registers storing integer
: values (assume no overflow). Your program may use an auxiliary register C in
: the computation. You may also label an instruction as a target of instruction
: JZ or JNZ. (15%)
: Instruction Meaning (X and Y are any two registers; L denotes a label)
: ADD X, Y Store the result of X + Y to X
: SUB X, Y Store the result of X – Y to X
: INC X Increase the value of X by one
: DEC X Decrease the value of X by one
: JZ X, L Jump to Label L if X = 0
: JNZ X, L Jump to Label L if X ≠ 0
: OUT X Output the value of X
: 請問這是要設計出A*B 用這指令集所擁有的指令? 並把結果寫入C?
: 那最後一句話 是要做什麼? 煩請高手解答一下
我不知道對不對,因為我沒有用到全部的指令
C初始為0
fuction(A,B)
{
Repeat:
JZ A , Output
ADD C , B
DEC A
JNZ A , Repeat
Output:
ADD A , C
OUT A
}
有錯請指教,感謝:)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.40.118.54
→ devilend:OUTPUT應該 直接OUT C就好吧 01/20 17:56
→ doubleday:因為我是為了配合題目才這樣寫,X=A,Y=B,OUT X = OUT A 01/20 18:34
推 tedmax100:感謝大大 提供的想法 ^^ 01/20 19:57