Machine language is brilliant, machine language is pure

See what the f***ing hell I've been fighting against for 6 hours this afternoon...

START a30

AT a20
; *a10 = '0' - 1;
000 001  0 000 101 111 ; load '0' #0x2F
001 010  0 000 001 000 ; store a10
; *a11 = '9';
000 001  0 000 111 001 ; load '9' #0x39
001 010  0 000 001 001 ; store a11

AT a30
; Read one byte into AC
110 101  0 000 000 010 ; trap 2

; Check for EOL
000 111  0 000 001 010 ; cmp o012
101 010  0 000 100 000 ; bne a40
110 101  0 000 000 001 ; trap 1, exit

AT a40
; isdigit || goto a60
; if AC <= '0' - 1 then goto a60
000 111  0 000 101 111 ; cmp 0x2F
101 100  0 000 110 000 ; ble a60
; if AC > '9' then goto a60
000 111  0 000 111 001 ; cmp 0x39
101 011  0 000 110 000 ; bgt a60
; is a digit. output and back
101 000  0 001 000 000 ; jmp a100
101 000  0 000 011 000 ; jmp a30

AT a60
; AC =~ /{+-*//}/ && goto a100
;; TODO
000 111  0 000 101 011 ; cmp '+'
101 001  0 001 000 000 ; beq a100
000 111  0 000 101 101 ; cmp '-'
101 001  0 001 000 000 ; beq a100
000 111  0 000 101 010 ; cmp '*'
101 001  0 001 000 000 ; beq a100
000 111  0 000 101 111 ; cmp '/'
101 001  0 001 000 000 ; beq a100
; fallback, read next char
101 000  0 000 011 000 ; jmp a30

AT a100
; display the char read and back to read
110 101  0 000 000 011 ; trap 3
101 000  0 000 011 000 ; jmp a30

The left half is machine instructions in binary form, and the seems-like-to-be-assembly statements are... comments!! I don't know what the hell are the pros in my faculty thinking... or they may just not be brave enough to let their assembler read my asm directly? Ummm...

By the way, this is the ML/Asm for a virtual machine developed by mostly FEIT @ ANU (the d*** s**** f****** s*** university I'm now studying in), with efforts from Sun Microsystems as well. I've seen somewhere on my course' website saying that this is the outcome of a project aiming to simulate the SPARC processor with software... I'm not sure if this really does the simulation or not

The virtual machine (called PeANUt, stupid, huh?) runs on the Solaris 9 server in my faculty ONLY, explaining that there are conflits of libraries when being built on Linux. It's written in C with TK so this might happen. I just don't understand why they don't do it with Java, like almost every other course from this faculty. Maybe I could put some time and port it to Java? Ummm, should be nice...

I've been reading the specificatoin from last night and finished this stupid assignment in 6 hours in my first try in the lab... Not too bad but I might do better (that means, less time) next time though.

The good side is that... This makes me getting interests about the asm and Java VM... Hope I would be able to take a course about VM design and implementation sometime later on...

ps. The most funny thing about PeANUt is that the extensions for assembly code files chosen by our pros... was ".ass", :lol:

An simplified algorithm

START a30

AT a30
; Read one byte into AC
110 101  0 000 000 010 ; trap 2

; Check for EOL
000 111  0 000 001 010 ; cmp o012
101 010  0 000 100 000 ; bne a40
; output an '/n' before exit
000 001  0 000 001 010 ; load #o012
110 101  0 000 000 011 ; trap 3
110 101  0 000 000 001 ; trap 1, exit

AT a40
; isdigit || match +-*/
; Since +-*/ and digits are almost in a continuous range in the
; ASCII encoding, I first test if the input is in this range
; lower range: '*'(o52)
; if AC <= o51 then discard
000 111  0 000 101 001 ; cmp 0x2F
101 100  0 000 011 000 ; ble a30
; upper range: '9'(o71)
; if AC > '9' then discard
000 111  0 000 111 001 ; cmp 0x39
101 011  0 000 011 000 ; bgt a30
; compare with holes in this range
; o54',' and o56'.'
000 111  0 000 101 100 ; cmp o54
101 001  0 000 011 000 ; beq a30
000 111  0 000 101 110 ; cmp o56
101 001  0 000 011 000 ; beq a30
; is a digit. output and back
; display the char read and back to read
110 101  0 000 000 011 ; trap 3
101 000  0 000 011 000 ; jmp a30
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值