HWK#2 Write a SISC program which can read 2 integers, and 
      then print out their sum and difference.
      Use SISC Emulator to run your program.

Due: 2010/04/13 (Tuesday)  

Description:
  Your program should:
   (1)Print out a greeting message including your student ID and your Name.
      Your name can be in Chinese or in English:-)
   (2)Prompt for 1st Number, and then read the 1st Number
   (3)Prompt for 2nd Number, and then read the 2nd Number
   (4)Print out sum of these 2 numbers
   (5)Print out the result of 1st Number - 2nd Number 
 Extra credit:
   (6) if both 1st# and 2nd# are zero, goto (8)
   (7) goto (2)
   (8) Print bye bye message.  
  Hint: 
    (a) Write it in assembly language format first.
    (b) And then translate it into SISC machine code manually.
       (Because we don't have an assembler for this language:-)
    (c) Download the SISC emulator SISC.EXE
        Execute the SISC.EXE  (if NOT work, try SISCx32.EXE)
    (d) in SISC emulator, type H for help, type I to see Instructions.
        type L to Load your machine code.
        Then, type G to run your machine code.
        You can also try other commands in SISC emulator.
    (e) The running script is in a LOG file SISC.LOG by default.
    (f) You also have to write the report in text or MSWord .doc format.

  注意: 本題請用 E-mail 繳交寄:  introcs.nctu@gmail.com
        信件標題(Subject:) 像這樣: HWK02 from 學號姓名(你學號接著姓名)
        注意 HWK02 五個字要連著不要有空格! 
        信件內容是你的心得, 其他要放一個壓縮檔, 當作夾檔附件:
        要先建立一個用你學號+題號名稱的子目錄, 例如 9917000HWK02
         把你所有檔案放在該子目錄內, 然後壓縮成 .zip 或 .rar 檔案,
         這個 .zip 檔或 .rar 檔當作你這次 mail 的夾檔 ;
        子目錄內須有: (心得也須出現在信件內容)
          00README.txt   -- 你的心得以及想告訴助教與老師的話
          hwk02.asm    --  你寫的組合語言原始檔
          hwk02.mc     -- 可以餵給 SISC.EXE 的機器碼檔案
          hwk02.log    -- 你的 running script
           注意 Running script 就是在執行完 SISC.EXE 後的 SISC.LOG
           如果你用 default 的名稱 SISC.LOG,
           請把它 rename 成 hwk02.log 再放入子目錄中!   

今天 2010/03/30 還有人在問進 SISC 目錄要抓什麼??? 會不會太扯了!? 這問題若是在兩三週前問, 我會很有耐心再講一遍! 都已經講過一個月了才來問? 太混了吧? 課堂上也 Demo 很多次了! 其實也不必問, 本頁底下就告訴你抓 sisc.zip 回去解壓就好了; 解壓縮後當然先看 00README.... 不過真正要用的只有 SISC.EXE 一個檔案啦! (可以只抓這隻SISC.EXE) 其他是給夠用功的同學看的, 包括許多 SISC 範例, SISC.EXE 的原始檔各版本, (SISC.EXE 是用 TurboPascal 寫的, 要抓patch 過的 TurboPascal) (已抓並 patch 過放 sisc/TurboPascal 下, 但沒放入 sisc.zip 壓縮檔內) sisc.zip 內還有一個以前你們學長用 SISC 寫的 BATNUM.MC, 另外, 還有也是以前你們學長用 Perl 寫的 SISC Assembler (組譯器), 該組譯器可以把 SISC 組語程式翻譯成 SISC machine code, 但是你必須照它定的規矩!
Sample program to print out it's memory content in decimal format: ;samp.asm --- by tsaiwn@csie.nctu.edu.tw ;SISC Emulator: http://www.csie.nctu.edu.tw/~tsaiwn/sisc/ ORG 0 ; start from address 0 (PC=0) LDI 1, 1 ; 2 1,01 ; R1=1 (00) LDI 2, 0 ; 2200 ; R2=0 (02) LDI 3, 58 ; 233A ; R3 = length of this program AGAIN: STORE 2, THERE+1 ; 3209 ; store r2 into 9 ; STORE 2, 9 THERE: LOAD 6,0 ; 16 00 ; LOAD r6 from ?? (:08 :09 ) LDI 0,'M' ; 20 4d ; r0="M" 或寫成 LDI 0, 77 或 LDI 0,$4d PUTC ; d1 00 ; print "M" LDI 0, '(' ; 20 28 ; "(" === LDI 0,40 或 LDI 0,$28 或 LDI 0,28h PUTC ; d100 ; print "(" (:10h) MOV 2,0 ; 40 20 ; move r2 to r0 (:12h) PUTI ; d300 ; print r0 as integer LDI 0, ')'; 20 29 ; ")" === LDI 0, 41 PUTC ; d1 00 LDI 0, '=' ; 203d;"=" === LDI 0, 61 或 LDI 0,3DH 或 LDI 0,$3D PUTC ; d1 00 MOV 6,0 ; 40 60 ; move r6 to r0 PUTI ; d300 ; print r0 as integer LDI 0,13 ; 200d; CR PUTC ; d1 00 LDI 0,10 ; 20 0A ;LF PUTC ; d1 00 MOV 3,0 ; 40 30 ; move r3 to r0 (program length) ADD 2,2,1 ; 5221 ; r2 := r2+1 (r1 contains 1) BR 2,OK ; B232 ; jump to OK if R2=R0 BR 0,AGAIN ; B006 ; goto AGAIN (always) OK: LDI 0,7 ; 2007 ; bell PUTC ; d1 00 HALT ; c000 ; halt END
Machine code format for the previous program: ;SAMP.MC ; simple SISC SAMPle program ;by Wen-Nung Tsai, tsaiwn@csie.nctu.edu.tw ;this is a sample Machine Code for the SISC ; that will print out the code of myself ; in decimal form 分號開始或空白行都會被忽略 2 1,01 ; R1=1 (00) 空白和逗號可出現於任何地方 2200 ; R2=0 (02) 233A ; R3 = length of this program 3209 ; store r2 into 9 (:AGAIN = 06) 16 00 ; LOAD r6 from ?? (:08 :09 ) 20 4d ; r0="M" d1 00 ; print "M" 20 28 ; "(" d100 ; print "(" (:10h) 40 2,0 ; move r2 to r0 (:12h) d300 ; print r0 as integer 20 29 ; ")" d100 203d;"=" d100 4060; move r6 to r0 d300 ; out content of mem[r2] (:20h) 200d; CR d100 20 0A ;LF d100 ; print Line Feed (:28h) 40 30 ; move r3 to r0 (program length) 5221 ; r2 := r2+1 (r1 contains 1) B232 ; jump to done if R2=R0=R3 b006 ; goto :AGAIN=06 (this line :30) 2007 ; bell (:done = 32) d100 ; beep the speaker c000 ; halt ffff ; for man check only ;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Sample program that will read an integer n and then print out sum of 1, 2, ... n ;samp2.mc ;; by tsaiwn@csie.nctu.edu.tw ;this machine program read N ; and calculate 1+2+...+N 2101 ; R1=1 (address 00:) d624 ; print string "N=" (address 02:) d200 ; read integer into R0 (address 04:) 29 01 ; R9 = 1 (address 06:) 2500 ; R5 = 0, used to store sum (address 08:) 5 5 5,9 ; R5 = R5 +R9 :again (0A:) B9 12 ; if done goto :ok 5991 ; R9 = R9 + 1 (0E:) B0 0a ; goto :again d6 28 ; print "Sum from 1 to " :ok (12:) d300 ; out int from R0 (14:) d625 ; print "=" (16:) 4050 ; move r5 to r0 , the sum (18:) d300 ; out int from R0 d620 ; out cr/lf c000 ; halt 0d0a ; CR/LF (:20h) 2424 ; $$ $ indicate String terminated 4e3d ; "N=" (:24h) 2424 ; $$ 5375 ; Su (:28h) 6d20 ; m 6672 ; fr 6f6d ; om 2031 ; 1 (:30h) 2074 ; t 6f20 ; o 2424 ; $$ c000 (:38h) ;end of this program ;
You are the -th visitors to this page.
SISC Emulator can be found here:
http://www.csie.nctu.edu.tw/~tsaiwn/sisc/
      其實只要抓 sisc.zip 就可以了:-)
2010/03/31 新增一個 32-bit version 執行檔 SISCx32.EXE
這個 SISCx32.EXE 應該可以在 64-bit 的 OS 上跑!
(在壓縮檔內也有, 別又跟我說找不到:-)

該檔案是用 Virtual Pascal 2.1 compile/link 的;
原始檔須略作修改, 自己看修改過的 SISCx32.PAS
(也在壓縮檔內, 不要跟我說找不到:-)

這裡有 以前你們學長用 perl 寫的 SISC assembler 加減可以用
回作業目錄       回課程目錄             Goto 物件導向課程(OOP)目錄