Machine language is brilliant, machine language is pure

來源:互聯網
上載者:User

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

START a30AT a20; *a10 = '0' - 1;000 001  0 000 101 111 ; load '0' #0x2F001 010  0 000 001 000 ; store a10; *a11 = '9';000 001  0 000 111 001 ; load '9' #0x39001 010  0 000 001 001 ; store a11AT a30; Read one byte into AC110 101  0 000 000 010 ; trap 2; Check for EOL000 111  0 000 001 010 ; cmp o012101 010  0 000 100 000 ; bne a40110 101  0 000 000 001 ; trap 1, exitAT a40; isdigit || goto a60; if AC <= '0' - 1 then goto a60000 111  0 000 101 111 ; cmp 0x2F101 100  0 000 110 000 ; ble a60; if AC > '9' then goto a60000 111  0 000 111 001 ; cmp 0x39101 011  0 000 110 000 ; bgt a60; is a digit. output and back101 000  0 001 000 000 ; jmp a100101 000  0 000 011 000 ; jmp a30AT a60; AC =~ /{+-*//}/ && goto a100;; TODO000 111  0 000 101 011 ; cmp '+'101 001  0 001 000 000 ; beq a100000 111  0 000 101 101 ; cmp '-'101 001  0 001 000 000 ; beq a100000 111  0 000 101 010 ; cmp '*'101 001  0 001 000 000 ; beq a100000 111  0 000 101 111 ; cmp '/'101 001  0 001 000 000 ; beq a100; fallback, read next char101 000  0 000 011 000 ; jmp a30AT a100; display the char read and back to read110 101  0 000 000 011 ; trap 3101 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",

An simplified algorithm

START a30AT a30; Read one byte into AC110 101  0 000 000 010 ; trap 2; Check for EOL000 111  0 000 001 010 ; cmp o012101 010  0 000 100 000 ; bne a40; output an '/n' before exit000 001  0 000 001 010 ; load #o012110 101  0 000 000 011 ; trap 3110 101  0 000 000 001 ; trap 1, exitAT 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 discard000 111  0 000 101 001 ; cmp 0x2F101 100  0 000 011 000 ; ble a30; upper range: '9'(o71); if AC > '9' then discard000 111  0 000 111 001 ; cmp 0x39101 011  0 000 011 000 ; bgt a30; compare with holes in this range; o54',' and o56'.'000 111  0 000 101 100 ; cmp o54101 001  0 000 011 000 ; beq a30000 111  0 000 101 110 ; cmp o56101 001  0 000 011 000 ; beq a30; is a digit. output and back; display the char read and back to read110 101  0 000 000 011 ; trap 3101 000  0 000 011 000 ; jmp a30

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.