Paint16b: A 16 byte paint program written in 12 lines
sizecoding.org
sizecoding.org
And something I found useful https://www.muppetlabs.com/~breadbox/software/tiny/teensy.ht...
It really is quite amazing how small you can make things when you try. Then you realise you're wasting most of a disc sector, and the thing you have is unportable and unmaintainable. But still, being able to look at a binary and know what every byte does, being unconstrained by the rules of a language is liberating.
I found this : https://developers.slashdot.org/story/12/02/19/1351213/tetri... but it's in Javascript.
A long time ago I wrote this : https://github.com/dalf/stetris/blob/master/STETRIS-UTF8.ASM
http://stanislavs.org/helppc/int_33.html
http://stanislavs.org/helppc/int_10.html
The main loop contains an implicit state-machine that does multiple things on different iterations, which is partly responsible for the small size.
Another thing that you can clearly see is how efficient it is at using the registers; this is one area where compiler-generated code is consistently behind, and something I wish compilers would get better at --- an HLL could take as many bytes as this entire program just to put the parameters onto the stack and call a function.
Finally, one small correction:
ret ; assume [[FFEE]] = [0] = CD20 = int 20
...should be "assume [FFFE] = 0", because that's where the stack pointer is initially, and this program does not use the stack itself for its entirety --- it doesn't need to! ; allows exit if the mouse is leftmosteither way cool! :D
Hmm. So the second time this program is run, it will fail?
Edit: I take that back. According to [1]:
.COM-format executables begin running with the following register values:
AL = 00h if first FCB has valid drive letter, FFh if not
AH = 00h if second FCB has valid drive letter, FFh if not
[0] https://thestarman.pcministry.com/asm/debug/debug.htm#INITThis online x86/x64 assembler is great: https://defuse.ca/online-x86-assembler.htm
And in the case of interpreted languages or JIT'd languages the lines get blurred a bit more but even there it is clear that whoever uses say 'numpy' does not need an understanding of the underlying operations to get through their working day.
Higher levels of abstraction translate into higher productivity, in ever more rare cases it is worth breaking open those black boxes to go to work on the underlying plumbing.
Registers might have different names depending on the platform, actual command names may vary, but I would be surprised to see non-obscure platforms for which the pattern above is not valid.
I only knew it was Assembly because i once looked at the apollo guidance computer's source code.
Confusing Asm with early (GOTO-only) BASIC, on the other hand, would seem far more common to me.
Look, I wrote assembly when I was a teen, went to school for CS twice and can't do squat with it today. I know it is ASM but beyond that it's not that interesting or exciting to me.
This person's job is strictly to build frontend web apps. Knowledge of assembly is largely ornamental to that pursuit. I'm not even sure someone getting as BSCS and MSCS would spend enough time with it to care.
It's important, critically so for some people, but I wouldn't ding a job applicant for a node job for not recognizing it.
2) Assembly is vastly more high level than modern hardware, so much that most of those CISC instructors are broken into tens to thousands micro operations. It's not even close to any kind of machine architecture course. You will need that kind of deep knowledge to write optimal compilers which probably take (extended) C and not assembly language.
And besides, with their question they’ve made an effort to learn about it so I don’t see any reason to criticize them for not knowing. It’s like the xkcd referenced says, every day there are a bunch of people hearing about something for the first time. We should be happy that they hear about it!
You also seem to be making the assertion that you cannot understand how a CPU works without knowing ASM, which seems equally spurious.
However, I would be shocked if anyone who went through a CS program wasn't aware of assembly programming.
Dosbox with it's default config should work fine.
> SizeCoding.org is a wiki dedicated to the art of creating very tiny programs for the 80x86 family of CPUs. By "very tiny programs", we mean programs that are 256 bytes or less in size, typically created by members of the demoscene as a show of programming skill. The size of these tiny programs is measured by their total size in opcode bytes, and are usually presented as executable .COM files to be run in pure DOS, a DOS VM running inside another operating system, or an emulator that can run DOS such as DOSBox.
#!/bin/bash
#
# Author: Martin "BruXy" Bruchanov, bruxy at regnet.cz
#
# Check input first
if [ ! $# -eq 1 ] || [ "$1" == "-h"] || [ "$1" == "--help" ] ; then
printf "Usage:\n"
printf "\t$0 saved_image\n"
printf "\n\tImage data will be saved into given filename, if file exist\n"
printf "\tit will be displayed and ready to edit!\n"
printf "\tHit <Ctrl-C> any time to quit the program.\n"
exit 1
fi
##################
# Initialization #
##################
IMAGE_FILE=$1
_STTY=$(stty -g) # Save current terminal setup
printf "\e[2J" # clear screen, set cursos at beginning
stty -echo -icanon # Turn off line buffering
printf "\e[?9h" # Enable terminal mouse reading
printf "\e[?25l" # Turn of cursor
printf "\e]0;-=[ ShPaint ]=-\007"
# Hash array with image data,
# ... key is "$Y;$X",
# ... value ANSI colors and brush "b;F;Bm"
declare -A IMAGE
# Defaults
BRUSHES=( )
FG=( {30..37} )
BG=( {40..47} ) # 49 ... default background
X=0
Y=0
ERASE=0
BRUSH=${BRUSHES[3]}
FG_COLOR="1;${FG[7]}"
BG_COLOR=49
#############
# Functions #
#############
function save_image() {
printf "\e[2J" > $IMAGE_FILE
for i in ${!IMAGE[@]}
do
printf "\e[${i}f\e[${IMAGE[$i]}\e[0m"
done >> $IMAGE_FILE
# set cursor under the image
printf "\e[$(tput lines);1f" >> $IMAGE_FILE
}
function at_exit() {
printf "\e[?9l" # Turn off mouse reading
printf "\e[?12l\e[?25h" # Turn on cursor
stty "$_STTY" # reinitialize terminal settings
clear
echo "Thank for using ansipaint!"
if [ ! -z "$IMAGE_FILE" ] ; then
echo "Your image is saved as '$IMAGE_FILE'."
save_image
fi
exit
}
# X = $1, Y = $2
function set_pos() {
echo -en "\e[$2;$1f"
}
function show_pos() {
set_pos 65 1
printf "x,y = %3d,%3d" $X $Y
}
function show_brush() {
set_pos 70 2
printf "[ \e[${FG_COLOR};${BG_COLOR}m$BRUSH\e[0m ]"
}
function process_click() {
# X=$1 Y=$2
# set foreground color
if [ $Y -eq 1 ] || [ $Y -eq 2 ] ; then
if [ $X -gt 2 ] && [ $X -lt 28 ] ; then
FG_COLOR="$[Y-1];${FG[$[(X-4)/3]]}"
ERASE=0
fi
fi
# set background color
if [ $Y -eq 1 ] && [ $X -gt 34 ] ; then
if [ $X -gt 34 ] && [ $X -lt 59 ] ; then
BG_COLOR="${BG[$[X-35]/3]}"
ERASE=0
else
BG_COLOR="49"
ERASE=0
fi
fi
# set brush
if [ $Y -eq 2 ] && [ $X -gt 36 ] && [ $X -le 51 ] ; then
BRUSH=${BRUSHES[$[(X-37)/2]]}
ERASE=0
fi
# set erase
if [ $Y -eq 2 ] && [ $X -ge 54 ] && [ $X -le 62 ] ; then
BRUSH=" "
BG_COLOR="49"
ERASE=1
fi
# DEBUG
# set_pos 0 25
# printf "$FG_COLOR $BG_COLOR $BRUSH"
}
function draw_menu() {
set_pos 1 1; echo "FG: "
for i in ${FG[*]}
do
set_pos $[(i-30)*3+4] 1
echo -en "\e[${i}m\e[0m"
set_pos $[(i-30)*3+4] 2
echo -en "\e[1;${i}m\e[0m"
done
set_pos 30 1; echo "BG: "
for i in ${BG[*]}
do
set_pos $[(i-40)*3+35] 1
echo -en "\e[${i}m \e[0m"
done
echo " |" # default background (49)
set_pos 30 2; echo -en "Brush: ${BRUSHES[*]}"
printf " [ Erase ]"
show_brush
}
function load_image() {
if [ -f $IMAGE_FILE ] ; then
data=$(sed -e 's/\x1b/E/g;s/E\[0m/\n/g;s/E\[2J//' $IMAGE_FILE | \
sed -n -e 's/E\[\(.*\)fE\[\(.*m.\)/IMAGE["\1"]="\2"/ p')
eval $data
cat < $IMAGE_FILE
fi
}
##########
# MAIN #
##########
trap at_exit ERR EXIT
load_image
draw_menu
while :
do
read -N 6 click
mouse=( `echo -en ${click#???} | hexdump -v -e'1/1 " %u"'` )
X=$[ ${mouse[0]} - 32] Y=$[ ${mouse[1]} - 32]
process_click
show_pos
show_brush
if [ $Y -gt 2 ] ; then
echo -en "\e[${Y};${X}f\e[${FG_COLOR};${BG_COLOR}m$BRUSH\e[0m"
if [ $ERASE -eq 0 ] ; then
IMAGE["${Y};${X}"]="${FG_COLOR};${BG_COLOR}m$BRUSH"
else
unset IMAGE["${Y};${X}"]
fi
fi
done
[0] http://bruxy.regnet.cz/web/linux/EN/ansi-art-sh-paint