我不确定我的错误在哪里,我正在尝试从0-255水平红色和0-255绿色垂直输出渐变图案。我知道链接文件正常工作,因为它们经过了彻底的测试。任何帮助都将非常感激。
global _start
global start
extern writeRGB
extern writeHeader
_start:
call start
sys_write: equ 1
sys_open: equ 2
sys_close: equ 3
sys_exit: equ 60
newLine : equ 10
section .data
filename: db "gradient.ppm", 0
section .bss
buffer: resb 4096
section .text
start:
push r12
push r13
push r14
push r15
push rbx
push rbp
mov rax, sys_open ; setup to open file
mov rdi, filename ; move filename
mov rsi, 577 ; given
mov rdx, 0o644 ; given
syscall ; open file
cmp rax, 0 ; check status
jl end
mov r12, 0 ; red
mov r13, 0 ; green
mov r14, rax ; opened file
mov r15, buffer ; buffer
mov rbx, 0 ; buffer counter
lea rdi, [r15+rbx] ; setup for writeheader call
mov rsi, 256
mov rdx, 256
call writeHeader
add rbx, rax ; add buffer space used by writeheader
call makeRGB ; create 0 0 0 rgb
lea rdi, [r15+rbx] ; setup for writeRGB
call writeRGB
add rbx, rax ; add buffer space used by writeRGB
call incRed
incRed:
call addSpace
inc r12 ; red++
call makeRGB ; convert to RBG
lea rdi, [r15+rbx] ; setup for writeRGB call
call writeRGB
add rbx, rax ; add buffer space used by writeRGB
cmp r12, 255 ; check to see if end of row
jl incRed ; if not end of row repeat
je incGreen ; if end of row start new row
incGreen:
cmp r13, 255 ; if last line is written move to end
je write
call addNewLine
mov r12, 0 ; reset red to 0
inc r13 ; green++
call makeRGB ; convert to RGB
lea rdi, [r15+rbx] ; setup for writeRGB call
call writeRGB
add rbx, rax ; add buffer space used by writeRGB
call addSpace
jmp incRed ; ret to incRed
makeRGB:
mov r12, rsi ; mov red into rsi
shl rsi, 8 ; shift left 8 to make room for green
add rsi, r13 ; add green
shl rsi, 8 ; shift left to set blue to 0
ret
addSpace:
mov al, ' ' ; insert space
mov [r15+rbx], al
inc rbx
ret
addNewLine:
mov al, newLine ; insert newline
mov [r15+rbx], al
inc rbx
ret
write:
mov rax, sys_write
mov rdi, r14 ; move opened file into rdi
mov rsi, r15 ; buffer location
mov rdx, rbx ; load buffer size
syscall ; write to file
mov rbp, rax ; status stored in rbp
cmp rbp, 0 ; check status
jl end
mov rdi, r14 ; move opened file into rdi
mov rax, sys_close ; close file
syscall
call end ; end
end:
pop rbp
pop rbx
pop r15
pop r14
pop r13
pop r12
mov rdi, rax ; prepare to exit
mov rax, sys_exit
syscall ; exit