Spread Firefox!

用Firefox已经很习惯了,IE反倒不舒服。Tabbed browsing,只打开一个实例就可以了。舒服的增量搜索,让我现在很不习惯大多数文本编辑或查看工具的搜索方式。还有一堆好用的插件,数不过来。

我现在安装的插件不多:

Tab Mix Plus–标签浏览
FlashGot–曾经因为Firefox缺乏多线程工具而痛苦,现在它已经做得很好了。
Google Toolbar for Firefox–搜索关键字提示,充分应用Firefox功能的页面关键字搜索,还有关键的一点,可以在网页上取词翻译,这可没有for IE
Gmail Manager–Gmail的管理、通知程序
FoxyTunes–在Firefox里控制你喜欢的音乐播放器,foobar2000/iTunes/WinAmp等等,一般的都支持。

索性今天就在Blog的侧栏加了一栏”No IE”和”Spread Firefox”的宣传图片,呵呵。希望更多的人开始认识Firefox,使用Firefox,并喜欢它。

Technorati : ,

猴子倒骑斑马

合肥野生动物园我去过两次,当时还没有现在的熊猫和白虎。让人觉得不错的是那个野兽园的观光大桥,听说现在上面卖鸡了,买了马上扔下去喂野兽,就几十块钱,呵呵。

园里的孔雀和鹿是到处跑的,小鹿看见人伸手就以为是人要喂它,就跑过来了。还有海狮馆的表演也很好。

有一次去的时候在猴园看,它跟斑马园是挨着的,猴子可以去斑马那边逛。当时一只斑马在中间的栏杆旁边散步,一个猴子看见了,就在栏杆上跟着它跑,跑着跑着瞅准了就跳到斑马背上去了。又一只猴子看见了,就抓着马尾巴也爬上去了。斑马大概已经习惯了,若无其事地继续走。前几天在论坛上看同学发的动物园照片,竟然又有这样的情景,保留下来,呵呵,这个挺像故事"张果老倒骑毛驴"的吧?如下:

monkey.jpg

合肥的怪异天气

昨晚睡觉没关阳台的门,早上还不知道8点就被雷声吵醒了。

中午的时候, 往外面一看,大吃一惊,天黑得跟晚上一样,以为是日食了呢,赶紧跑出去看。可是日食应该会有预报的,原来是云层太厚了。各大网站上都报道了这个现象,呵呵。在合肥最讨厌它的天气了,不过今天让我长了见识:)

下面是两张网上复制的图片(新华网):

Img242634350.jpg Img242634351.jpg

还有几张是同学在东区理化大楼拍的:

雨前1.jpg 雨前2.jpg

雨前3.jpg

代码生成器的弱智错误

中缀表达式计算的翻译存在严重问题,以前的想法是,右操作数计算结果放在%ebx中,左操作数结果放%eax,再根据运算符计算即可。但仔细想想便知道,计算左操作数时,仍可能用到%ebx,所以是不可行的。

现在是把左操作数的结果放在栈上,维护一个临时空间的表,表的大小根据需要的最多临时变量确定。

目前可以翻译了,递归函数也没问题。以上问题是由于用一个binary Euclid’s algorithm求最大公约数的算法做测试而发现的,呵呵。这个算法比较有个性,不同于常见的辗转相除法。具体见
http://www.cut-the-knot.org/blue/binary.shtml

开始设计实验了

Berkeley的实验已经做到可以接受函数参数及返回值、局部变量了,不准备再继续做面向对象特性了,而开始做计算机系实验的设计。
感觉这个难度更大了,要考虑的事情更多。现在应该把玩的心收一收,集中精力完成毕业设计。如果做完得早,说不定还可以出去做兼职赚点小钱,哈哈。

The simplest working compiler!

比较弱智,呵呵。
源程序如下:

class Program {
static int i;
static int j;
static boolean b;

static void Main() {
i = 3 * 5;
j = i + 10;
func();
print(j);
}
static void func() {
print(i);
}
}

翻译成汇编码:

.section    .rodata
format:
.string    "%dn"
.text
.globl main
.type    main, @function
main:
pushl    %ebp
movl    %esp, %ebp
subl    $8, %esp
movl    $3, %eax
movl    %eax, %ebx
movl    $5, %eax
imull    %ebx, %eax
movl    %eax, i
movl    i, %eax
movl    %eax, %ebx
movl    $10, %eax
addl    %ebx, %eax
movl    %eax, j
call    func
movl    j, %eax
movl    %eax, 4(%esp)
movl    $format, (%esp)
call    printf
leave
ret
.globl func
.type    func, @function
func:
pushl    %ebp
movl    %esp, %ebp
subl    $8, %esp
movl    i, %eax
movl    %eax, 4(%esp)
movl    $format, (%esp)
call    printf
leave
ret
.local    i
.comm    i, 4, 4
.local    j
.comm    j, 4, 4
.local    b
.comm    b, 4, 4

GAS编译的第一个汇编小程序

在Linux里写了第一个汇编小程序,呵呵,输入两个数字,计算出结果并显示。
保存为example.s,
# gcc -o example example.s

.section	.rodata
prompt:
.string	"Please input an integer:"
format:
.string	"%d"
oform:
.string "%d + %d = %dn"
.text
.globl main
.type	main, @function
main:
pushl	%ebp
movl	%esp, %ebp
subl	$32, %esp
andl	$-16, %esp
movl	$0, %eax
subl	%eax, %esp	;Instructions above have nothing meaningful.

movl	$prompt, (%esp)
call	printf		;Prompt for the first integer.
movl	%esp, %eax
addl	$20, %eax
movl	%eax, 4(%esp)
movl	$format, (%esp)
call	scanf		;Accept the first input.
movl	$prompt, (%esp)
call	printf		;Prompt for the second.
movl	%esp, %eax
addl	$16, %eax
movl	%eax, 4(%esp)
movl	$format, (%esp)
call	scanf		;Accept the second.
movl	16(%esp), %eax
addl	20(%esp), %eax	;Compute the sum of two integers
movl	%eax, 12(%esp)	;sum
movl	16(%esp), %eax
movl	%eax, 8(%esp)	;num2
movl	20(%esp), %eax
movl	%eax, 4(%esp)	;num1
movl	$oform, (%esp)
call	printf		;printf("%d + %d = %dn", num1, num2, sum);
leave
ret

AT&T assembly syntax

记得以前是弄过Windows里的汇编的,还调用了printf。现在不知道为什么不会弄了,只好转入Linux。现转载一篇AT&T语法格式的介绍(原文 h
ttp://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html ):

Register naming:

Register names are prefixed with “%”. To reference eax:

AT&T: %eax

Intel: eax

Source/Destination Ordering:

In AT&T syntax (which is the UNIX standard, BTW) the source is always on
the left, and the destination is always on the right.

So let’s load ebx with the value in eax:

AT&T: movl %eax, %ebx

Intel: mov ebx, eax

Constant value/immediate value format:

You must prefix all constant/immediate values with “$”.

Let’s load eax with the address of the “C” variable booga, which is static.

AT&T: movl $_booga, %eax

Intel: mov eax, _booga

Now let’s load ebx with 0xd00d:

AT&T: movl $0xd00d, %ebx

Intel: mov ebx, d00dh

Operator size specification:

You must suffix the instruction with one of b, w, or l to specify the width of
the destination register as a byte, word or longword. If you omit this, GAS
(GNU assembler) will attempt to guess. You don’t want GAS to guess, and guess
wrong! Don’t forget it.

AT&T: movw %ax, %bx

Intel: mov bx, ax

The equivalent forms for Intel is byte ptr, word ptr, and dword ptr, but that
is for when you are…

Referencing memory:

DJGPP uses 386-protected mode, so you can forget all that real-mode addressing
junk, including the restrictions on which register has what default segment,
which registers can be base or index pointers. Now, we just get 6 general
purpose registers. (7 if you use ebp, but be sure to restore it yourself or
compile with -fomit-frame-pointer.)

Here is the canonical format for 32-bit addressing:

AT&T: immed32(basepointer,indexpointer,indexscale)

Intel: [basepointer + indexpointer*indexscale + immed32]

You could think of the formula to calculate the address as:

immed32 + basepointer + indexpointer * indexscale

You don’t have to use all those fields, but you do have to have at least 1 of
immed32, basepointer and you MUST add the size suffix to the operator!

Let’s see some simple forms of memory addressing:

  • Addressing a particular C variable:

AT&T: _booga

Intel: [_booga]

Note: the underscore (“_”) is how you get at static (global) C variables from
assembler. This only works with global variables. Otherwise, you can use
extended asm to have variables preloaded into registers for you. I address
that farther down.

  • Addressing what a register points to:

AT&T: (%eax)

Intel: [eax]

  • Addressing a variable offset by a value in a register:

AT&T: _variable(%eax)

Intel: [eax + _variable]

  • Addressing a value in an array of integers (scaling up by 4):

AT&T: _array(,%eax,4)

Intel: [eax*4 + array]

  • You can also do offsets with the immediate value:

C code: *(p+1) where p is a char *

AT&T: 1(%eax) where eax has the value of p

Intel: [eax + 1]

  • You can do some simple math on the immediate value:

AT&T: _struct_pointer+8

I assume you can do that with Intel format as well.

  • Addressing a particular char in an array of 8-character records:

eax holds the number of the record desired. ebx has the wanted char’s offset
within the record.

AT&T: _array(%ebx,%eax,8)

Intel: [ebx + eax*8 + _array]

Whew. Hopefully that covers all the addressing you’ll need to do. As a note,
you can put esp into the address, but only as the base register.

锻炼身体,好好学习

上大学后体质越来越差了,上学期竟得了气胸,唉。
最近决定每天早上打会篮球,昨天早上去了,中午没睡觉,结果今天早上没起来,中等补打了会,呵呵。坚持下去,身体会好起来的。
记得高中的时候,在家里摸那个房梁,可以超半截手指的,这次回家只摸到了一次,后来再也摸不到了。。。