본문 바로가기

Programming Language

[Assembly] 배열선언 및 숫자더하기 실행환경- cpu : 인텔계열(64bit)- 컴파일러 : nasm- 리눅스 : ubuntu 16.04 LTS 설치방법- sudo apt-get install nasm 컴파일- nasm -f elf64 파일명.asm -o 파일명.o --> 목적파일을 만든다.- ld 파일명.o -o 파일명 --> 실행파일을 만든다. array.asmsection .bss result resb1section .datax: db 2,3,4end db 0ahsection .textglobal _start _start:;배열 정보를 가져와서 함계를 출력해 본다.;초기화 부분mov eax,3;값이 3개가 들어있으니 3번 돌리겠다라고 가정한다.mov ebx,0;값을 더해주기 위한 공간 mov ecx,x;x가 가르키는 것은? --> 배.. 더보기
[Assembly] 숫자 더하기 실행환경- cpu : 인텔계열(64bit)- 컴파일러 : nasm- 리눅스 : ubuntu 16.04 LTS 설치방법- sudo apt-get install nasm 컴파일- nasm -f elf64 파일명.asm -o 파일명.o --> 목적파일을 만든다.- ld 파일명.o -o 파일명 --> 실행파일을 만든다. addDouble.asmsection .datafirst db 'first : 'len1 equ $ -firstsecond db 'second : 'len2 equ $ -secondthird db 'third : 'len3 equ $ -thirdend db 0x0asection .bssnum1 resb 5;초기화 되지 않은 bss영역에서 5byte만큼 공간을 할당하겠다라는 의미num2 resb .. 더보기
[Assembly] 짝수 홀수 판별2 실행환경- cpu : 인텔계열(64bit)- 컴파일러 : nasm- 리눅스 : ubuntu 16.04 LTS 설치방법- sudo apt-get install nasm 컴파일- nasm -f elf64 파일명.asm -o 파일명.o --> 목적파일을 만든다.- ld 파일명.o -o 파일명 --> 실행파일을 만든다. EvenOddcmp.asmsection .datanum db "num : "len1 equ $ -numeven db "even"len2 equ $ -evenodd db "odd"len3 equ $ -oddend db 0ahsection .bssinput resb 1temp resb 1section .textglobal _start _start:;num 출력mov eax,4mov ebx,1mov .. 더보기
[Assembly] 짝수 홀수 판별1 실행환경- cpu : 인텔계열(64bit)- 컴파일러 : nasm- 리눅스 : ubuntu 16.04 LTS 설치방법- sudo apt-get install nasm 컴파일- nasm -f elf64 파일명.asm -o 파일명.o --> 목적파일을 만든다.- ld 파일명.o -o 파일명 --> 실행파일을 만든다. EvenOdd.asmsection .bssinput resb 1temp resb 1section .datanum db "num : "len1 equ $ -numodd db "odd "len2 equ $ -oddeven db "even "len3 equ $ -evenend db 0ahsection .textglobal _start _start:;num 출력mov eax,4mov ebx,1mov e.. 더보기
[Assembly] 문자열 변환 실행환경- cpu : 인텔계열(64bit)- 컴파일러 : nasm- 리눅스 : ubuntu 16.04 LTS 설치방법- sudo apt-get install nasm 컴파일- nasm -f elf64 파일명.asm -o 파일명.o --> 목적파일을 만든다.- ld 파일명.o -o 파일명 --> 실행파일을 만든다. ex1_6.asmSYS_WRITE equ4;#define SYS_WRITE 4와 같은 의미SYS_STDOUT equ 1SYS_READ equ3SYS_EXIT equ1 section .datamsg db 'hello world 'len equ $ -msgend db 0x0a section .bss section .textglobal _start _start:mov eax,SYS_WRITEmov e.. 더보기
[Assembly] * 찍어보기 실행환경- cpu : 인텔계열(64bit)- 컴파일러 : nasm- 리눅스 : ubuntu 16.04 LTS 설치방법- sudo apt-get install nasm 컴파일- nasm -f elf64 파일명.asm -o 파일명.o --> 목적파일을 만든다.- ld 파일명.o -o 파일명 --> 실행파일을 만든다. ex1_2.asmsection .data msg db "star 10 ", 0x0A len equ $ -msg;msg의 길이를 len이라는 변수가 가지는데 ;equ는 상수란 의미이다. 쉽게 equ는 equal와 같으며;$ -변수 은 변수의 길이를 구하기 위한 명령어라 생각하자;즉 len = $ -msg 은 msg의 길이가 상수로 len에 대입된다. star times 10 db '*'; time.. 더보기
[Assembly] Hello World 출력하기 실행환경- cpu : 인텔계열(64bit)- 컴파일러 : nasm- 리눅스 : ubuntu 16.04 LTS 설치방법- sudo apt-get install nasm 컴파일- nasm -f elf64 파일명.asm -o 파일명.o --> 목적파일을 만든다.- ld 파일명.o -o 파일명 --> 실행파일을 만든다. ex1_1.asmsection .data ;데이터 영역msg db "Hello World" , 0x0A ;msg == 변수 이름 , db == 데이터 타입(byte) , 0x0a == 개행문자 ;db == byte(1바이트) , dw == word(4바이트) , dd == double(8 바이트) section .textglobal _start _start:mov eax, 4 ;4번은 sys_w.. 더보기
[Assembly] 어셈블리 명령어 어셈블리 명령어는 다음과 같다. 더보기
[Assembly] syscall table for x86_64 리눅스 64비트에서 어셈블리로 프로그래밍을 할때 각함수의 이름과 레지스터 사용법이다. syscall로 실행해야 한다. %raxSystem call%rdi%rsi%rdx%rcx%r8%r90sys_readunsigned int fdchar *bufsize_t count1sys_writeunsigned int fdconst char *bufsize_t count2sys_openconst char *filenameint flagsint mode3sys_closeunsigned int fd4sys_statconst char *filenamestruct stat *statbuf5sys_fstatunsigned int fdstruct stat *statbuf6sys_lstatfconst char *filenamest.. 더보기
[Assembly] syscall table for x86 리눅스에서 어셈블리로 컴파일을 할떄 system call number을 알아야 하는데 32비트에서는 int 0x80으로 실행을 한다.(여기서 int는 interrupt의 약자이다.) 이 system call number 가 정이되어 있는 곳은 \usr\include\asm\unistd.h 에 지정되어 있다. %eaxNameSource%ebx%ecx%edx%esx%edi1sys_exitkernel/exit.cint----2sys_forkarch/i386/kernel/process.cstruct pt_regs----3sys_readfs/read_write.cunsigned intchar *size_t--4sys_writefs/read_write.cunsigned intconst char *size_t--5s.. 더보기