醒也罢 梦也罢 人生苦短
开始设计实验了
Berkeley的实验已经做到可以接受函数参数及返回值、局部变量了,不准备再继续做面向对象特性了,而开始做计算机系实验的设计。 感觉这个难度更大了,要考虑的事情更多。现在应该把玩的心收一收,集中精力完成毕业设计。如果做完得早,说不定还可以出去做兼职赚点小钱,哈哈。
醒也罢 梦也罢 人生苦短
Berkeley的实验已经做到可以接受函数参数及返回值、局部变量了,不准备再继续做面向对象特性了,而开始做计算机系实验的设计。 感觉这个难度更大了,要考虑的事情更多。现在应该把玩的心收一收,集中精力完成毕业设计。如果做完得早,说不定还可以出去做兼职赚点小钱,哈哈。
比较弱智,呵呵。 源程序如下: 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
在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
记得以前是弄过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 “$”. ...
上大学后体质越来越差了,上学期竟得了气胸,唉。 最近决定每天早上打会篮球,昨天早上去了,中午没睡觉,结果今天早上没起来,中等补打了会,呵呵。坚持下去,身体会好起来的。 记得高中的时候,在家里摸那个房梁,可以超半截手指的,这次回家只摸到了一次,后来再也摸不到了。。。