[英]Why doesn't jl work in asm x86 when by my calculations it should
I'm new to assembly and can't understand why jl decrement_year
and jl decrement_month
don't seem to work... I'm doing my homework for uni in asm x86 and when comparing the ref to my output the answers are either right or bigger by 1 (they're correct only if I didn't need to use the jumps).我是组装新手,不明白为什么
jl decrement_year
和jl decrement_month
似乎不起作用...我正在为 asm x86 中的 uni 做功课,当将参考文献与我的 output 进行比较时,答案是正确的或大 1 (仅当我不需要使用跳跃时它们才是正确的)。 This is only part of the program and the result should be a vector of ages calculated from the present day (day/month/year) and a list of birthdays (day/month/year).这只是程序的一部分,结果应该是从现在(日/月/年)计算的年龄向量和生日列表(日/月/年)。
mov edx, dword 0
mov ebx, dword 1
get_all_ages1:
mov eax, dword [esi + my_date.day] ; eax = present.day
sub eax, dword [edi + edx*my_date_size + my_date.day] ; eax -= dates[idx].day
test eax, eax
mov eax, dword [esi + my_date.month] ; eax = present.month
jl decrement_month ; cmp < 0 => eax -= 1
get_all_ages2:
sub eax, dword [edi + edx*my_date_size + my_date.month] ; eax -= dates[idx].month
test eax, eax
mov eax, dword [esi + my_date.year] ; eax = present.year
jl decrement_year ; cmp < 0 => eax -= 1
get_all_ages3:
sub eax, dword [edi + edx*my_date_size + my_date.year] ; eax -= dates[idx].year
test eax, eax
jle set_age_0 ; if present.year - dates.year <= 0 put 0
mov [ecx + edx*4], dword eax ; else put eax
jmp decrement_idx
decrement_idx:
add edx, 1
cmp edx, [ebp + 8]
jl get_all_ages1 ; if idx < len repeat
jmp stop ; end program
; here I can put any code I don't want used by accident
set_age_0:
mov [ecx + edx*4], dword 0 ; put 0 at all_ages[idx]
jmp decrement_idx
decrement_month:
sub eax, ebx
jmp get_all_ages2
decrement_year:
sub eax, ebx
jmp get_all_ages3
mov eax, dword [esi + my_date.day] mov eax, dword [esi + my_date.month] mov eax, dword [esi + my_date.year]
sub eax, dword [edi + edx*my_date_size + my_date.day] sub eax, dword [edi + edx*my_date_size + my_date.month] sub eax, dword [edi + edx*my_date_size + my_date.year]
How can these all be dwords ?这些怎么可能都是双字? Is the size of your my_date struct maybe 12?
您的my_date结构的大小可能是 12 吗? How would using 12 as a scaled index work?
使用 12 作为比例索引如何工作?
Assuming my_date_size == 4
:假设
my_date_size == 4
:
movzx eax, byte [esi + my_date.day]
movzx ebx, byte [edi + edx*my_date_size + my_date.day]
sub eax, ebx
...
movzx eax, byte [esi + my_date.month]
movzx ebx, byte [edi + edx*my_date_size + my_date.month]
sub eax, ebx
...
movzx eax, word [esi + my_date.year]
movzx ebx, word [edi + edx*my_date_size + my_date.year]
sub eax, ebx
...
decrement_month:
dec eax
jmp get_all_ages2
decrement_year:
dec eax
jmp get_all_ages3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.