“消息”块有问题,它的输出(print_less、print_more、print_equal、print_final)。我真的不知道如何存储字符串,所以这就是为什么我在输出中获取所有字符串而不是其中的两个(print_less 或 print_more 或 print_equal + print_final)。
这是代码:
format ELF64 executable
;=============================================
;================== DATA =====================
;=============================================
segment readable writeable
;=============================================
;=============================================
; variables
;=============================================
a dq 26h
b dq 100h
c dq 4h
d dq 3h
;=============================================
; messages
;=============================================
msg_less db 'a < b',0xA,0
msg_more db 'a > b',0xA,0
msg_equal db 'a = b',0xA,0
msg_final db 'Completed successfully',0xA,0
;=============================================
; message sizes
;=============================================
msg_more_size = $-msg_more
msg_less_size = $-msg_less
msg_equal_size = $-msg_equal
msg_final_size = $-msg_final
;=============================================
;================== CODE =====================
;=============================================
segment readable executable
;=============================================
entry $
_begin:
mov rcx,[a]
cmp rcx,[b]
jl print_less
jg print_more
je print_equal
_final:
mov edx,msg_final_size
lea rsi,[msg_final]
mov edi,1 ; STDOUT
mov eax,1 ; sys_write
syscall
jmp syscall_exit
;=============================================
; print message segment
;=============================================
print_less:
mov edx,msg_less_size
lea rsi,[msg_less]
jmp syscall_msg
print_more:
mov edx,msg_more_size
lea rsi,[msg_more]
jmp syscall_msg
print_equal:
mov edx,msg_equal_size
lea rsi,[msg_equal]
jmp syscall_msg
;=============================================
; syscall segment
;=============================================
syscall_msg:
mov edi,1 ; STDOUT
mov eax,1 ; sys_write
syscall
jmp _final
syscall_exit:
xor edi,edi ; exit code 0
mov eax,60 ; sys_exit
syscall
输出:
[look@me ~]$ fasm ~/workspace/ASM/ASM1/asm.asm && ~/workspace/ASM/ASM1/asm
flat assembler version 1.70.03 (16384 kilobytes memory)
3 passes, 364 bytes.
a < b
a > b
a = b
Completed successfully
Completed successfully