浏览代码

added number conversion and endless loop?

Phil 5 年之前
父节点
当前提交
60dc19e59e
共有 1 个文件被更改,包括 43 次插入7 次删除
  1. 43 7
      dino.asm

+ 43 - 7
dino.asm

@@ -6,7 +6,12 @@ STDOUT equ 1
 SYS_IOCTL equ 54
 
 section .bss
-	sz RESW 4 ; 4 byte for window size
+	sz RESB 4 ; 4 byte for window size
+	num resb 4 ;4 byte for ascii numbers
+
+section .data
+	ha dw 0 ;hundreds
+	ta dw 0 ;tens
 
 section .text
 	global _start
@@ -19,15 +24,36 @@ _start:
 	mov edx, sz		; target struct
 	int 0x80		; call kernel
 
+	;mov [ha], dword 0x0
+	;mov [ta], dword 0x0
+
 	; print rows
+hundreds:
+	mov ecx, [sz+0]		;rows in ecx
+	cmp ecx, 100		;check if above 100
+	jge inchundred		;jump to increment hundreds if needed
+	
+	mov eax,[ha]		;hundred count to eax
+	add eax, '0'		;convert to ascii
+	mov [num+0], eax	;move to first byte of num string
+
+tens:
+	cmp ecx, 10		;check if above 10
+	jge inctens		;jump to increment tens if needed
+	
+	mov eax,[ta]
+	add eax, '0'
+	mov [num+1], eax
 
-	mov ecx, [sz]
-	add ecx,'0'	
+	mov eax, ecx
+	add eax, '0'
+	mov [num+2], eax	
+	mov [num+3], dword 0xa 	;linebreak
 
 	mov eax, SYS_WRITE
 	mov ebx, STDOUT
-	;mov ecx, [sz]
-	mov edx, 2
+	mov ecx, num
+	mov edx, 4
 	int 0x80
 
 	; print cols
@@ -36,8 +62,8 @@ _start:
 
 	mov eax, SYS_WRITE
 	mov ebx, STDOUT
-	mov ecx, [sz+2]
-	mov edx, 2
+	mov ecx, sz+2
+	mov edx, 3
 	int 0x80
 
 exit:
@@ -45,3 +71,13 @@ exit:
 	mov eax, 1
 	mov ebx, 0
 	int 0x80
+
+inchundred:
+	inc dword [ha]		;increment hundreds
+	sub ecx, 100
+	jmp hundreds
+
+inctens:
+	inc dword [ta]		;increment hundreds
+	sub ecx, 10
+	jmp tens