gloss_num_ntos

This commit is contained in:
neza 2023-03-11 00:13:12 +03:00
parent 308eedd5f2
commit 11c20479b6
6 changed files with 46 additions and 53 deletions

View File

@ -18,7 +18,7 @@ $(TARGET) : $(OBJ)
.PHONY : clean, echo, ready
clean :
rm -f $(TARGET) .*~ *~ src/*.o src/.*~ src/*~
rm -f $(TARGET) *~ src/*.o src/*~
echo :
echo $(T)

View File

@ -14,8 +14,8 @@ Assemble:
```shell
$ make
```
Change the number of attempts from 6 (default value).
Select T in range 5-9:
Change the default number of attempts.
Select T in range 5 to 9:
```shell
$ make clean
$ make T=7
@ -28,7 +28,7 @@ Run:
```shell
$ ./guess
```
Return code - random number.
Return value: 0 - success, 1 - failure.
*Make the fork,*
*come up with a feature*

View File

@ -3,63 +3,18 @@
conv:
push %rbp
mov %rsp, %rbp
sub $8, %rsp
push %rdi
push %rsi
mov $bye_len, %rsi
mov $bye, %rdi
call say
pop %rsi
pop %rdi
call ntosn
mov %edi, 4(%rsp)
mov 4(%rsp), %eax
xor %rdx, %rdx
mov $100, %ecx
divw %cx
cmp $0, %ax
je .l2
mov $4, %esi
add $48, %eax
movb %al, (%rsp)
movb $48, 1(%rsp)
movb $48, 2(%rsp)
movb $10, 3(%rsp)
lea (%rsp), %rdi
call say
jmp .l0
.l2:
mov %edx, %eax
xor %rdx, %rdx
mov $10, %ecx
divw %cx
cmp $0, %ax
je .l1
mov $3, %esi
add $48, %eax
movb %al, (%rsp)
add $48, %edx
movb %dl, 1(%rsp)
movb $10, 2(%rsp)
lea (%rsp), %rdi
call say
jmp .l0
.l1:
mov $2, %esi
add $48, %edx
movb %dl, (%rsp)
movb $10, 1(%rsp)
lea (%rsp), %rdi
call say
.l0: leave
pop %rbp
ret
.data
bye: .ascii "It was "
bye_len = . - bye

View File

@ -1,3 +1,4 @@
//sleep
.text
.globl slip
slip:

37
src/num.s Normal file
View File

@ -0,0 +1,37 @@
//print number ntosn (with new line) or ntos (without nl)
.text
.globl ntosn, ntos
ntos: mov $1, %r9
jmp .l0
ntosn: xor %r9, %r9
.l0: push %rbp
mov %rsp, %rbp
mov %rdi, %rax
mov $10, %ebx
xor %r8, %r8
mov $-38, %rdx
.l1:
dec %r8
add $48, %rdx
movb %dl, (%rbp,%r8)
xor %rdx, %rdx
div %rbx
cmp $0, %rax
jg .l1
add $48, %rdx
dec %r8
movb %dl, (%rbp,%r8)
mov $1, %eax
mov $1, %edi
lea (%rbp,%r8), %rsi
add %r9, %r8
neg %r8
mov %r8, %rdx
syscall
pop %rbp
ret

View File

@ -25,7 +25,7 @@ scan:
dec %eax
mov %eax, %ecx
mov %eax, %r9d
mov %eax, %r9d
xor %rax, %rax
movq $0, -16(%rbp)
movl $10, -8(%rbp)