在汇编程序 [英] program on Assembly
问题描述
有人可以请解释一下这个程序是干什么的?
can somebody please explain what this program is doing?
.= torg + 1000
main:
mov pc, sp
tst –(sp)
mov #list1, -(sp)
jsr pc, mystery
mov r0, res1
tst (sp)+
mov #list2, -(sp)
jsr pc, mystery
mov r0, res2
tst (sp)+
halt
mystery:
mov r1, -(sp)
mov r4, -(sp)
mov r5, -(sp)
clr r0
mov 10(sp), r4
mov r4, r5
loop:
mov r4, r1
jsr pc, next
mov r1, r4
beq return
mov r5, r1
jsr pc, next
jsr pc, next
mov r1, r5
beq return
cmp r4, r5
beq setret
br loop
setret:
inc r0
return:
mov (sp)+, r5
mov (sp)+, r4
mov (sp)+, r1
rts pc
next:
tst r1
beq abort
mov (r1), r1
abort:
rts pc
.= torg + 3000
list1: .word 3006, 3000, 3002, 3004, 0
res1: .word -1
.= torg + 3020
list2: .word 3030, 3026, 0, 3024, 3022
res2: .word -1
我不能提前给大家明白这个片段中,由于
I can't understand this snippet, thanks in advance for everyone
mystery:
mov r1, -(sp)
mov r4, -(sp)
mov r5, -(sp)
clr r0
mov 10(sp), r4
mov r4, r5
推荐答案
这似乎是备份寄存器1,4和5和初始化寄存器0(其不需要进行备份)。由于 @mystery
是 JSR
,这就是所谓的序幕code 。然后,它们被初始化为循环
It appears to be backing up registers 1, 4, and 5 and initializing register 0 (which doesn't need to be backed up). Since @mystery
is the destination of a jsr
, this is called prologue code. Then, they are initialized for the loop.
旧值在 @返回
恢复。
至于整个程序在做什么,它似乎在寻找一个链表循环链接。
As for what the whole program does, it appears to find cyclic links in a linked list.
bool is_invalid_list( link_node *l ) {
while ( l && l->next && l->next->next ) {
if ( l->next == l->next->next ) return true;
}
return false;
}
我不认为这是实现这一点无论还不是最坏的最简单的或最佳方式,但
I don't think this is the simplest or best way to implement this, but not the worst either.
这篇关于在汇编程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!