[ASM] AT&T assembly syntax

기본 형식

가장 큰 차이점은 operands의 순서이다.
Intel-syntax가 mnemonic destination, source 인데 반해, AT&T Syntax의 일반적인 형식은 다음과 같다.

mnemonic source, destination

레지스터

모든 IA-32 아키텍처의 레지스터 이름은 앞에 ‘%’가 붙는다.

mov %ax, %bx

위의 예제는 16비트 레지스터 AX로부터의 값을 16비트 레지스터 BX로 옮긴다.

상수 값

모든 상수 값들은 앞에 ‘$’가 붙는다.

mov $100, %bx
mov $A, %al

메모리 주소지정

AT&T 문법에서 메모리는 다음 방식으로 참조된다.

segment-override:signed-offset (base,index,scale)

일부는 생략 가능하다.

%es:100 (%eax,%ebx,2)

offset과 scale은 앞에 ‘$’가 붙으면 안된다.

GAS memory operand         NASM memory operand
------------------          -------------------

100                 [100]
%es:100                 [es:100]
(%eax)                  [eax]
(%eax,%ebx)             [eax+ebx]
(%ecx,%ebx,2)               [ecx+ebx*2]
(,%ebx,2)               [ebx*2]
-10(%eax)               [eax-10]
%ds:-10(%ebp)               [ds:ebp-10]

예제

mov    %ax,    100
mov %eax,   -100(%eax)

첫번째 예제는 ax 레지스터의 값을 (기본인) data segment 레지스터의 offset 100으로 옮기는 것이다.

두번째 예제는 eax 레지스터의 값을 [eax-100]으로 옮기는 것이다.

Operand 크기

상수 값을 메모리로 옮길 때, size-of-transfer나 operand-size를 지정할 필요가 있다. 다음 예제에서는 transfer size는 없고, 값 10을 메모리 offset 100으로 옮기는 것만 지정되어 있다.

mov    $10,    100

NASM에서는 캐스팅 키워드 byte / word / dword 등을 붙여서 이를 한다. AT&T 문법에서는 이를 instruction에 suffix b/w/l을 붙여서 한다. 예를 들면 다음은 byte 값 10을 [ea:eax] 위치로 옮긴다

movb   $10,    %es:(%eax)

다음은 long 값 10을 같은 위치로 옮긴다.

movl   $10,    %es:(%eax)

아래도 그 예제들이다.

movl   $100, %ebx
pushl   %eax
popw    %ax

제어를 넘기는 Instructions

jmp, call, ret 같은 instruction들은 프로그램의 한 곳에서 다른 곳으로 제어를 넘긴다. 이는 같은 코드 세그먼트 (near) 로 또는 다른 코드 세그먼트 (far) 로 제어를 넘길 수 있다. 가능한 브랜치 주소 지정 타입은 relative offset (label), register, memory oerand, 그리고 segment-offset pointers이다.

Relative offsets은 아래처럼 labels을 사용한다.

label1:
    .
    .
  jmp   label1

Register나 memory operands를 사용하는 브랜치 주소 지정은 ‘*’를 앞에 붙여야만 한다. “far” 제어 넘김을 지정하기 위해서는 ‘ljmp’, ‘lcall’ 등과 같이 ‘l’을 앞에 붙여야 한다. 다음이 그 예제이다.

GAS syntax         NASM syntax
==========          ===========

jmp *100            jmp  near [100]
call    *100            call near [100]
jmp *%eax           jmp  near eax
jmp *%ecx           call near ecx
jmp *(%eax)         jmp  near [eax]
call    *(%ebx)         call near [ebx]
ljmp    *100            jmp  far  [100]
lcall   *100            call far  [100]
ljmp    *(%eax)         jmp  far  [eax]
lcall   *(%ebx)         call far  [ebx]
ret             retn
lret                retf
lret $0x100         retf 0x100

Segment-offset pointers는 다음 형식을 사용해서 지정한다:

jmp    $segment, $offset

다음이 그 예제이다.

jmp    $0x10, $0x100000

더 자세한 GNU assembler에 대해서 더 자세히 알고 싶으면 문서를 참고하자.

 

참고: https://csiflabs.cs.ucdavis.edu/~ssdavis/50/att-syntax.htm

[Raspbian] ibus-hangul로 한글 입력 설정

Raspbian 설치하고 언어를 바로 Korean으로 설정하고 하라는대로 재부팅하면 폰트가 설치되어 있지 않아서 메뉴가 다 깨져보여서 보기 힘들다. 난 그냥 English를 사용하도록 한 후, 필요한 걸 설치했다.

입력기가 요즘 또 새로운게 생겨서 fcitx를 쓸 수도 있는 것 같던데, ibus-hangul을 설치했다.

sudo apt-get install ibus-hangul

 

재부팅하면 트레이에 ibus 아이콘이 보인다. 기본은 English다.

우클릭 / “Preferences” / “Input Method” / “Add” / “…” / “Korean” 을 하면 태극 무늬의 “Korean” 이 추가된다.

English는 제거하자.

한영키는 별도 설정없이 기본으로 한영키를 쓰면 한글과 영문이 토글된다.

Shift + space도 된다.

 

[Raspbian] Can’t locate Gtk3.pm in @INC

Synaptic 깔고 패키지 설치해보면 아래와 같은 에러가 뜬다.

해결방법은 libgtk3-perl 패키지를 설치해주면 된다.

 

debconf: unable to initialize frontend: Gnome
debconf: (Can’t locate Gtk3.pm in @INC (you may need to install the Gtk3 module) (@INC contains: /etc/perl /usr/local/lib/arm-linux-gnueabihf/perl/5.28.1 /usr/local/share/perl/5.28.1 /usr/lib/arm-linux-gnueabihf/perl5/5.28 /usr/share/perl5 /usr/lib/arm-linux-gnueabihf/perl/5.28 /usr/share/perl/5.28 /usr/local/lib/site_perl /usr/lib/arm-linux-gnueabihf/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Gnome.pm line 151, <> line 3.)

 

참고: https://www.linuxquestions.org/questions/bodhi-92/can%27t-locate-gtk3-pm-4175657312/

[Raspbian] 기본 사용자인 ‘pi’ 지우기

Raspbian 설치 후에 기본 사용자인 pi를 지우고, 내 아이디를 쓰고 싶어서 지워봤다.

ssh 같은거 열면 pi로 막 들어올까봐…

모든 작업은 root로 진행했다.

 

  1. 내 ID 추가

adduser dasomoli

  1. 내 ID를 sudo 그룹으로 넣기

usermod -aG sudo dasomoli

  1. pi 사용자와 같은 그룹으로 만들기
    cat /etc/group | grep pi
    usermod -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio dasomoli

  2. polkit local authority 설정

vi /etc/polkit-1/localauthority.conf.d/60-desktop-policy.conf

AdminIdentities=unix-group:sudo;unix-user:0

  1. lightdm 설정

vi /etc/lightdm/lightdm.conf

autologin-user=dasomoli

  1. systemd 설정

vi /etc/systemd/system/autologin@.service

ExecStart=-/sbin/agetty –autologin dasomoli –noclear %I $TERM

vi /etc/systemd/system/getty@tty1.service.d/autologin.conf

ExecStart=-/sbin/agetty –autologin dasomoli –noclear %I $TERM

  1. 재부팅 후 내 ID로 로그인

  2. pi 지우기

deluser –remove-home –remove-all-files pi

delgroup pi

 

참고: https://www.raspberrypi.org/forums/viewtopic.php?t=202618

[vi] .vimrc

.vimrc 같은건 대충 필요한 것만 그때 그때 써서 썼는데 새 환경에서 하나하나 쓰려니 귀찮다. 복사해서 쓸 수 있게 여기다 하나 써두고 업데이트하자.

syntax on

set autoindent
set cindent
:set smartindent
set noexpandtab

set nu

set hlsearch

set ts=4
set shiftwidth=4

set laststatus=2
set statusline=\ %<%l:%v\ [%P]%=%a\ %h%m%r\ %F\
set incsearch

colorscheme elflord

set tags=./tags,tags
set tags+=/usr/src/linux/tags
set tags+=../tags
set tags+=../../tags
set tags+=../../../tags

highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/

https://medium.com/sunhyoups-story/vim-%EC%97%90%EB%94%94%ED%84%B0-%EC%9D%B4%EC%81%98%EA%B2%8C-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-5b6b8d546017

[Windows] Command Prompt의 Current Code page 변경

Windows에서 명령줄을 띄워서 작업할 때, 어떤 에러 메시지 등을 google에서 찾아보고 싶은 경우 같은 때, 나오는 메시지의 언어를 바꾸고 싶을 때가 있다. 이럴 때 “LANG” 환경 변수 등을 바꾸어도 그대로 에러 메시지 등이 우리말로 나온다. 요건 mingw 같은 환경에서 shell을 써도 마찬가지. 한국판 Windows를 깔면 기본이 CP949로 설정되어 에러 메시지 등이 우리말로 나오는 것인데, 다음과 같이 CHCP 명령을 이용하면 된다. 65001은 UTF-8이다.

CHCP 65001

참고: https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8