assembly - 整数乘法和索引寻址
问题描述
我的老师给我们分配了这张工作表,这真的给我带来了麻烦。我很难确切地知道我应该从什么乘或除索引指令,然后根据它确定溢出。
例如在字母 E 上,我们有
imulw 12(%ebx, %edx, 8)
并且更改的寄存器是 dx:ax 因为操作数大小是 16 位。答案是
0004:CA63
但我无法理解 0004 的来源。
解决方案
你被问到电脑会做什么。所以问问电脑它会做什么(https://youtu.be/xaVgRj2e5_s?t=167):
# Linux:
# Name: computer.s (capital S if compiled in Windows)
# Compile: gcc -m32 -o computer computer.s
# Run: ./computer (Don't forget dot-slash!)
#if defined(__WIN32__)
#define main _main
#define printf _printf
#endif
.data
arr: .long 0x5, 0x7, 0x8, 0xD, 0x9, 0xC1A55ED, 0xDECADE, 0xFADEDBAD, 0x700300, 0x400800
fmt: .string "%c % 4X % 8X:%- 8X OF=%c\n"
.text
.global main
main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp # Space for 6 DWORD à 4 byte
andl $-16, %esp # Align stack to 16
E: call init
lea 12(%ebx,%edx,8), %edi # Claculate the operand and store it in EDI
movl $arr, %ebx # Modify EBX to point to arr
imulw 12(%ebx, %edx, 8) # Do it
seto %cl # Store the overflow flag in CL
or $0x30, %cl # To ASCII
movzwl %ax, %eax # Clear garbage in EAX
movzwl %dx, %edx # Clear garbage in EDX
movl $fmt, 0(%esp) # Fill the stack with arguments for printf
movl $'E', 4(%esp)
movl %edi, 8(%esp)
movl %edx, 12(%esp)
movl %eax, 16(%esp)
movl %ecx, 20(%esp)
call printf # Call a C function
leave # Restore the stack
xor %eax, %eax # Return 0;
ret # Only valid when compiled with a compiler (GCC)
init:
movl $0x4F, %eax
movl $0x500, %ebx
movl $0x1, %ecx
movl $0x2, %edx
ret
推荐阅读
- git - 是否可以使用 `git cat-file -p` 的 `master^{tree}` 语法来打印 blob?
- javascript - 有什么方法可以限制wordpress中的不同IP?
- database - 在 Rust 中使用 oracle crate
- python - 在地图上聚类位置,其中每个聚类具有相同数量的点
- javascript - 正则表达式检测 Zalgo
- leaflet - 在传单 [r] 中绘制 sf 类型的对象
- bytecode - Dalvik 字节码和比较为 0 跳转
- reactjs - OpenID Connect 与 .Net Core 3 和 React
- logging - kubectl 为 pod 中的特定容器记录“未找到首选地址”
- java - 使用 Junit 5 和 spring boot 2 在 Mokito 2 中未找到测试