装配简单的项目,seg错误

时间:2016-03-03 20:33:54

标签: assembly x86 computer-science cpu-registers

我正在尝试为我的集会课做作业,老师的例子有一行

movl (%eax),%ebx

我的代码使用完全相同的行,但每当gdb到达它时,我都会遇到seg错误。我不明白为什么。请帮我。这是整个代码,通过QEMU在32位Linux上运行。

.text
.byte 12, 0x12, 012
.word 34, 0x34, 034
L1:
.long 23, 0x23, 023
.global _start
_start:
  # do not change, remove or add anything other than specifying the underscores
  movl $0x1700121C,%eax  #hex for 385880604
  movl (%eax),%ebx       #moving contents of eax into ebx, long to long
  movw 0x17,%bx          #attemtping to move via memory location (probably buggy)
  movb $0x12,%bh

  # at this point, %ebx should have the value of 385880604
checkHere:

  movl $1,%eax
  movl $0,%ebx
  int  $0x80

请帮忙。谢谢你的时间。

2 个答案:

答案 0 :(得分:0)

" movl $ 0x1700121C,%eax #hex for 385880604"需要引用标签/内存地址。

答案 1 :(得分:0)

此分配的目标是以给定值({ "size": 0, "aggs": { "group_by_vendor": { "terms": { "field": "vendor" }, "aggs": { "max_run_number": { "terms": { "field": "run_number", "order": {"_term": "desc"}, "size": 1 }, "aggs" : { "top hits agg" : { "top_hits" : { "size" :3 } } } } } } } } )填充某个寄存器(0x1700121C)。

当程序运行时,它可以放在内存中的任何位置,用于程序和它分配的内存(例如,用于变量)。

你告诉它要看一个绝对的地址,这不是你想要的。您实际上并不知道您的程序及其分配的RAM字节在何处结束。您想在此处使用相对地址。 (在引擎盖下,可执行文件标题中的一些信息可以帮助实现这一点,如果你很好奇的话)

但你怎么得到相对地址?您可以利用ebx。您不知道其确切的数字地址,但您确实知道它从L1开始的任何地方开始。您可以在.long 23上进行数学运算以获取相对地址。由于在内存L1指向的地方之前有一些字节,因此您需要减去。

L1是2个字节,其中有3个字节,加上之前有3个字节,因此.word - 9可以转到此数据的第一个字节。

相关问题