
laba2_v2.s
Код:
;===================DATA SECTION======================
SECTION .data
char db 0
;===================TEXT SECTION======================
SECTION .text
global _start
;this func read char from STDIN and
;return char in char
readchar:
;readchar prolog
push eax
push ebx
push ecx
push edx
;if we do not read any char from STDIN
;char = 0
mov byte[char], 0
;call sys_read(0, char, 1)
mov eax, 3
mov ebx, 0
mov ecx, char
mov edx, 1
int 0x80
;readchar epilog
pop edx
pop ecx
pop ebx
pop eax
ret
;this func read number from STDIN
;while user do not press Enter
readnum:
readchcycle:
call readchar
;user press Enter
cmp byte[char], 13
jne readchcycle
ret
_start:
call readnum
;call sys_exit(0)
mov eax, 1
mov ebx, 0
int 0x80
Makefile
Код: Выделить всё
AS=nasm
LD=ld
BIN=laba2
ASFLAGS=-f elf -g
LDFLAGS=-o $(BIN)
SRC=laba2_v2.s
OBJ=laba2_v2.o
BIN=laba2
all: $(SRC)
$(AS) $(ASFLAGS) $(SRC)
$(LD) $(LDFLAGS) $(OBJ)
.PHONY: clean
clean:
rm -f $(OBJ) \
$(BIN)
NASM version 2.05.01 compiled on Nov 5 2008
GNU gdb 6.8-debian
Copyright © 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
Ubuntu 9.04