๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ 42seoul ํ”„๋กœ์ ํŠธ

[42seoul] libasm : assembly(์–ด์…ˆ๋ธ”๋ฆฌ)๋ฅผ ํ™œ์šฉํ•œ ๋ช‡ ๊ฐœ์˜ ํ•จ์ˆ˜ ๊ตฌํ˜„

by kukim 2021. 10. 28.

0๏ธโƒฃ1๏ธโƒฃ libasm

@42seoul : (2020.11.20 ~ 2020.12.01)

๐Ÿ“– About

  • ์ด ํ”„๋กœ์ ํŠธ๋Š” ์–ด์…ˆ๋ธ”๋ฆฌ ์–ธ์–ด๋ฅผ ๊ฐ€์ง€๊ณ  ๋ช‡ ๊ฐ€์ง€ ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.(The aim of this project is to get familiar with assembly language.)
Type Function Description
  ft_strlen.s man strlen
  ft_strdup.s man strdup
  ft_strcpy.s man strcpy
  ft_strcmp.s man strcmp
  ft_write.s man write
  ft_open.s man open
  • write, read ํ•จ์ˆ˜๋Š” systemcall ํ˜ธ์ถœํ•˜๊ณ  error ๋ฐœ์ƒ ์‹œ __error ํ˜ธ์ถœํ•˜์—ฌ errno๋ฅผ ์ €์žฅํ•˜๊ณ  ๋๋‚ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“ Review

  • assembly language๋ฅผ ๊ฒฝํ—˜ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.
  • Computer-Achitecture ์Šคํ„ฐ๋””๋„ ํ•จ๊ป˜ ์ง„ํ–‰ํ–ˆ๋‹ค.
  • CPU, ๋ ˆ์ง€์Šคํ„ฐ, Stack ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ดํ•ดํ•˜๊ฒŒ ๋˜์—ˆ๊ณ  read, writeํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด์„œ ๊ฐ๊ฐ์˜ ์‹œ์Šคํ…œ์ฝœ ๋ฒˆํ˜ธ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์ปค๋„๋ชจ๋“œ๋กœ ๋ณ€๊ฒฝ ๋˜๋ฉฐ sys_open() ์ปค๋„ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜๊ณ  ํ•จ์ˆ˜๊ฐ€ ๋๋‚˜๋ฉด ๋‹ค์‹œ ์‚ฌ์šฉ์ž ๋ชจ๋“œ๋กœ ๋ฐ”๋€Œ๊ณ  ๊ฒฐ๊ณผ๊ฐ€ ๋ฆฌํ„ด๋œ๋‹ค. ์ด๋•Œ ์‹œ์Šคํ…œ์ฝœ์ด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์บ๋ฆฌํ”Œ๋ž˜๊ทธ๊ฐ€ ๋ฐœ์ƒ๋˜๊ณ  rax ๋ ˆ์ง€์Šคํ„ฐ์— errno๊ฐ€ ๋“ค์–ด์žˆ๋‹ค. ์ด๊ฒƒ์„ __error๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ error๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ณ€์ˆ˜์— rax ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•œ ๋’ค ์ตœ์ข…์ ์œผ๋กœ -1์„ ๋ฆฌํ„ดํ•˜๊ณ  ์ข…๋ฃŒ๋œ๋‹ค.
  • Level 0 ํ”„๋กœ์ ํŠธ Libft์—์„œ ๋งŒ๋“ค์—ˆ๋˜ ft_strlen๊ณผ Libc์˜ strlen ๋ฒค์น˜๋งˆํฌ ๊ฒฐ๊ณผ ์™„ํŒจํ–ˆ๋Š”๋ฐ ๊ทธ ์ด์œ ๊ฐ€ ์–ด์…ˆ๋ธ”๋ฆฌ ๋‹จ์—์„œ ์ตœ์ ํ™” ๊ณผ์ •์„ ๊ฑฐ์ณค๊ธฐ ๋•Œ๋ฌธ์ด์ง€ ์•Š์„๊นŒ ํ•œ๋‹ค.

๐Ÿ Run

  • Assembly Env
    • nasm compiler
    • x86_64 macos
    • intel
  • Unit-test : Libc - ์–ด์…ˆ๋ธ”๋ฆฌ ๊ตฌํ˜„ ํ•จ์ˆ˜ ๋น„๊ต
    libasm

โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ ft_read.s
โ”œโ”€โ”€ ft_strcmp.s
โ”œโ”€โ”€ ft_strcpy.s
โ”œโ”€โ”€ ft_strdup.s
โ”œโ”€โ”€ ft_strlen.s
โ”œโ”€โ”€ ft_write.s
โ”œโ”€โ”€ libasm.h
โ””โ”€โ”€ main.c


๐Ÿ”— Reference

๐Ÿง‘๐Ÿป‍๐Ÿ’ป Author

kukim

ํƒœ๊ทธ

,

๋Œ“๊ธ€0