section .text
global _start
_start:
mov eax, [inputOrder]
mov ecx, inputOrder
mov edx, inputLen
mov ebx, 1
mov eax, 4
int 0x80
mov eax, 1
mov ebx, 0
int 0x80
section .data
inputOrder db 065,066,067,068,069,070,071,072,073,074,075,076,077,078,079,080,081,082,083,084,085,086,087,088,089,090
inputLen equ $ - inputOrder
I need help. I need to use loop in order to print out A-Z. What is the needed code in order to solve this issue? What will I add in this code in order to make a Loop rather than inputOrder?
CodePudding user response:
First you write down what the code would be without loop, and then you generalize it so loop can be used.
Today, nobody uses loop because it’s utterly slow, but if you insist on using loop:
global _start
bits 64
default rel
section .text
shr edx, 2 ; edx ≔ edx div 4
test ecx, ecx ; ZF ≔ ecx = 0
print:
mov [rsi], rbp ; rsi↑ ≔ rbp
mov eax, edi ; eax ≔ edi
mov esp, ecx ; esp ≔ ecx
syscall ; fast system call
; rax, rcx, and r11 are not preserved
mov ecx, esp ; ecx ≔ esp
lea rbp, [rbp rbx] ; rbp ≔ rbp rbx
loopne print ; ecx ≔ ecx − 1
; if ecx ≠ 0 ∧ ¬ZF then goto print
jecxz $$ ; if ecx = 0 then goto $$
shr edi, 1 ; edi ≔ edi div 2
exit:
mov eax, 60 ; eax ≔ 60
syscall
_start:
mov rbp, 'ABCDEFGH' ; rbp ≔ 16#4847464544434241
mov rbx, 0x0808080808080808 ; rbx ≔ 16#0808080808080808
mov ecx, 3 ; ecx ≔ 3
setne dil ; dil ≔ ¬ZF
mov dl, bl ; dl ≔ bl
mov rsi, rsp ; rsi ≔ rsp
jmp print ; goto print
CodePudding user response:
mov eax, [inputOrder]
This instruction loads the EAX register with 0x44434241, but then you simply don't use it. To be removed.
A loop as per request, would output a single character, increment the ASCII code for the character and continue until the Z character got processed. There's no need to use an actual loop instruction!
Again:
mov edx, 1
mov ecx, TheChar
mov ebx, 1
mov eax, 4
int 0x80
movzx eax, byte [TheChar]
inc eax
cmp al, 'Z'
jbe Again
xor ebx, ebx
mov eax, 1
int 0x80
section .data
TheChar db 'A'
