我在一个装配类,我需要打印一个白色字符“一堆”为我正在做的项目。我已经在这里坐了几个小时了,试图使printW函数工作,所以它被称为X次。下面的代码将打印出2“s,将初始cx更改为任意数字,不会更改代码打印的"*"s的数量。我快疯了。请有人找出代码的问题,并解释为什么它是一个问题?
printBoard:
mov ecx,0x00010
cmp ecx,0
loop printWhiteRow
ret
printWhiteRow:
call printW
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;print a string
printW:
push ebp ; set up stack frame
mov ebp,esp
mov eax, whiteChar ; put a from store into register
push eax ; value of variable a
call printf ; Call C function
add esp, 8 ; pop stack 3 push times 4 bytes
mov esp, ebp ; takedown stack frame
pop ebp ; same as "leave" op
ret ; return发布于 2015-11-11 00:35:27
一些问题:
loop指令是如何工作的。add esp, 8 ; pop stack 3 push times 4 bytes。3乘4等于12,在任何情况下,你只推了一个论点。ecx定义为调用方保存,因此,如果要保存其值,则需要保存它。putchar?像这样的事情应该更好地发挥作用:
printBoard:
mov ecx,0x00010
printWhiteRow:
push ecx ; save counter
push ' ' ; char to print
call putchar
pop ecx ; cleanup argument
pop ecx ; restore counter
loop printWhiteRow
ret同样适用于printf
printBoard:
mov ecx,0x00010
printWhiteRow:
push ecx ; save counter
push whiteChar ; string to print
call printf
pop ecx ; cleanup argument
pop ecx ; restore counter
loop printWhiteRow
rethttps://stackoverflow.com/questions/33642172
复制相似问题