CSC231 Loop Offset is +127/-128 bytes
--D. Thiebaut 09:35, 15 October 2012 (EDT)
- The LOOP instruction can only take you to a label that is +127 or -128 bytes away!
1 ;;; printStars.asm
2 ;;; D. Thiebaut
3 ;;;
4 ;;;
5 ;;;
6 ;;; To assemble, link, and run:
7 ;;; nasm -f elf -F stabs printStars.asm
8 ;;; ld -melf_i386 -o printStars printStars.o
9 ;;; ./printStars
10 ;;;
11
12 section .data
13
14 00000000 0A2A2A2A2A2A2A2A2A- stars db 0x0a, "******************************"
15 00000009 2A2A2A2A2A2A2A2A2A-
16 00000012 2A2A2A2A2A2A2A2A2A-
17 0000001B 2A2A2A2A
18 starsLen equ $-stars
19
20 0000001F [00000000] addr dd stars
21 00000023 1F000000 count dd starsLen
22
23 section .text
24 global _start
25 _start:
26 00000000 8B0D[23000000] mov ecx, dword[count]
27
28 00000006 890D[23000000] for: mov dword[count], ecx
29 0000000C B804000000 mov eax, 4
30 00000011 BB01000000 mov ebx, 1
31 00000016 B9[00000000] mov ecx, stars
32 0000001B 8B15[23000000] mov edx, dword[count]
33 00000021 CD80 int 0x80
34
35 00000023 8B0D[23000000] mov ecx, dword[count]
36 00000029 E2DB loop for
37
38 ;;; exit
39 0000002B BB00000000 mov ebx, 0
40 00000030 B801000000 mov eax, 1
41 00000035 CD80 int 0x80
42
43
If you want to loop farther away, then you need to use JMP!