computer system 4

//ex7_1
#include "stdio.h"
void main( ){ 
    int ix=-0x25432,iy,iz;
    short sx;
    unsigned uix,uiy,uiz;
    unsigned short usx;
    
    sx=ix;//n>m,截断
    iy=sx; //n<m,符号扩展
    uix=ix; //n=m,直接传送
    
    usx=uix;//n>m,截断
    uiy=usx; //n<m,零扩展

    iz=usx; //n<m,零扩展
    uiz=sx; //n<m,符号扩展

    printf("ix=%d,iy=%d,iz=%d\n",ix,iy,iz);
    printf("sx=%d\n",sx);
    printf("uix=%u,uiy=%u,uiz=%u\n",uix,uiy,uiz);
    printf("usx=%u\n",usx);
}

在这里插入图片描述

//ex7_2
#include "stdio.h"
void main( ){   
    int ix= -0x25432,iy=0;
    float fx=0,fy=0;  
    asm (   "mov -0x18(%ebp),%eax\n\t"  
            "mov %eax,-0x10(%ebp)\n\t"
    );  
    fy=ix;            
    iy=fy;                 
    printf("ix=%d,iy=%d\n",ix,iy);
    printf("fx=%f,fy=%f\n",fx,fy);
}

student1@506-55:~$ vim ex7_2.c
student1@506-55:~$ gcc -O0 ex7_2.c -m32 -g -o ex7_2
student1@506-55:~$ objdump -S ex7_2>ex7_2.txt
student1@506-55:~$ gdb ex7_2
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ex7_2...done.
(gdb) break 12
Breakpoint 1 at 0x8048495: file ex7_2.c, line 12.
(gdb) run
Starting program: /home/student1/ex7_2 
ix=-152626,iy=-152626
fx=-nan,fy=-152626.000000

Breakpoint 1, main () at ex7_2.c:12
12	}
(gdb) x/1xw &ix
0xbfffef70:	0xfffdabce
(gdb) x/1xw &iy
0xbfffef74:	0xfffdabce
(gdb) x/1xw &fx
0xbfffef78:	0xfffdabce
(gdb) x/1xw &fy
0xbfffef7c:	0xc8150c80

在这里插入图片描述

//ex8
#include "stdio.h"
int add(int x, int y) {
    asm(
        "mov  8(%ebp),%eax\n\t"
        "add  0xC(%ebp),%eax\n\t"
    );
        return x+y;
}

int sub(int x, int y) {
    asm(
        "mov  8(%ebp),%eax\n\t"
        "sub  0xC(%ebp),%eax\n\t"
    );
        return x-y;
}

int main(){
    int ax=2147483647,ay=1,az;
    unsigned aux=2147483646,auy=2,auz;
    int sx=3,sy=4,sz;
    unsigned sux=5,suy=6,suz;
    az=add(ax,ay);
    auz=add(aux,auy);
    printf("%d+%d=%d,%u+%u=%u\n",ax,ay,az,aux,auy,auz);
    sz=sub(sx,sy);
    suz=sub(sux,suy);
    printf("%d-%d=%d,%u-%u=%u\n",sx,sy,sz,sux,suy,suz);
    return 0;
}

在这里插入图片描述在这里插入图片描述

student1@506-55:~$ gdb ex8
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ex8...done.
(gdb) break 7
Breakpoint 1 at 0x8048414: file ex8.c, line 7.
(gdb) run
Starting program: /home/student1/ex8 

Breakpoint 1, add (x=2147483647, y=1) at ex8.c:7
7			return x+y;
(gdb) i r ebp
ebp            0xbfffef40	0xbfffef40
(gdb) x/1xw $ebp+8
0xbfffef48:	0x7fffffff
(gdb) x/1xw $ebp+12
0xbfffef4c:	0x00000001
(gdb) i r eax
eax            0x80000000	-2147483648
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) n
Program not restarted.
(gdb) c
Continuing.

Breakpoint 1, add (x=2147483646, y=2) at ex8.c:7
7			return x+y;
(gdb) i r eax ebp
eax            0x80000000	-2147483648
ebp            0xbfffef40	0xbfffef40
(gdb) x/1xw $ebp+12
0xbfffef4c:	0x00000002
(gdb) x/1xw $ebp+8
0xbfffef48:	0x7ffffffe
(gdb) break 16
Breakpoint 2 at 0x804842d: file ex8.c, line 16.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) n
Program not restarted.
(gdb) c
Continuing.
2147483647+1=-2147483648,2147483646+2=2147483648

Breakpoint 2, sub (x=3, y=4) at ex8.c:16
16	}
(gdb) i r eax ebp
eax            0xffffffff	-1
ebp            0xbfffef38	0xbfffef38
(gdb) x/1xw $ebp+8
0xbfffef40:	0x00000003
(gdb) x/1xw $ebp+12
0xbfffef44:	0x00000004
(gdb) c
Continuing.

Breakpoint 2, sub (x=5, y=6) at ex8.c:16
16	}
(gdb) x/1xw $ebp+8
0xbfffef40:	0x00000005
(gdb) i r eax ebp
eax            0xffffffff	-1
ebp            0xbfffef38	0xbfffef38
(gdb) x/1xw $ebp+12
0xbfffef44:	0x00000006
(gdb) break 29
Breakpoint 3 at 0x804850a: file ex8.c, line 29.
(gdb) c
Continuing.
3-4=-1,5-6=4294967295

Breakpoint 3, main () at ex8.c:29
29		return 0;
(gdb) x/1xw &az
0xbfffef70:	0x80000000
(gdb) x/1xw &auz
0xbfffef74:	0x80000000
(gdb) x/1xw &sz
0xbfffef78:	0xffffffff
(gdb) x/1xw &suz
0xbfffef7c:	0xffffffff
(gdb) q
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值