Doing time traveling with assembly language
Sergels Torg, Stockholm

Doing time traveling with assembly language

I’m taking a distance course at the University in Ume? learning about Linux for development (https://www.umu.se/utbildning/kurser/linux-som-utvecklingsmiljo-1/). The course is covering a lot and it’s been big fun to do the exercises and the teachers are great. Some exercises is about coding in C and some involve debugging. Anyway, firing off the debugger inspired me to dust off my old assembler “skills”.

My first memories from programming was in the early 80’s. Doing BASIC programming on a computer at school. Later on I got my 8-bit ZX Spectrum with 48K memory (https://en.wikipedia.org/wiki/ZX_Spectrum), but it all really started with my first IBM PC. It was a Model 5155 – a “portable” one weighing over 13 kilos (https://en.wikipedia.org/wiki/IBM_Portable_Personal_Computer). No hard drive, but two floppy drives, and it was on this setup I learned 16-bit 8088 assembly language 35 years ago. I still have the book I started to learn from.

No alt text provided for this image

Of course it’s an understatement to say that a lot has happened since the mid 80’s. It’s more than “a lot”. It amazes me when I reflect on the evolution of IT and computer hardware.

Me in Boca Raton, Florida in the early 90s

Me in Boca Raton, Florida in the early 90s

But let’s focus on one of the smallest building blocks. The CPU. This is how I briefly summarize the journey.

The Intel 8088 was a 16-bit CPU with four 16bit registers (AX, BX, CX, DX) and three segment registers (CS, DS, SS). Then the 80286 came, still 16-bit, and with the 80386 (i386) we entered the 32-bit world. At that time I ran OS/2, and developers talked about “thunking” and how to mix 16-bit and 32-bit code. A phenomenon that actually was well-known by the mainframe community who had been doing it in OS/370 (OS/390 and z/OS) since the 70s, and they wondered about all the fuzz about it. Then the 80486 (i486) came. It was still 32-bit, and the same with Pentium (IA-32). Now we are on a 64-bit architecture with the IA-64 (X86-64).

Going back in time to IBM PC DOS 3.3 (mid 80’s)

There are many ways to run 16-bit DOS programs, and I chose to install it in a virtual machine. Booting the diskette, and installing the system on a virtual hard drive. Welcome back to the 80’s!

I installed Microsoft Macro Assembler from 1985 and wrote my first 16-bit assembler program in many years. Just a simple “hello world”. As you can see below the executable (.EXE) is 544 bytes. Compact stuff, and it actually prints the hello world message. Success

No alt text provided for this image

IBM DOS 3.3

Above you can see the HELLO.EXE file, but I also created the H1.COM, which is another kind of executable. The .EXE file is the standard executable format, but there is also the more compact COM file format. The COM file format was inherited from the CP/M operating system which was built in the 70s.

Hello world as an .EXE file

This is how my small program looks. Hello world is defined as msg and located in the data segment. In the code, I first set up the data segment. Then the message is printed and at the end the program is terminated.

.model small
.stack 100H

.data

msg db 'Hello World', 0dh, 0ah, '$'

.code 

main 	proc 
	mov ax,@data
	mov ds,ax

	lea	dx, msg
	mov ah,9
	int 21h

	mov ah,4ch

	int 21h

main 	endp
	end main        

The .exe file is created by running masm and link, like illustrated below.

No alt text provided for this image

Running masm and link

Hello World as a .COM file

The COM file is more or less the same. Since it only contains one segment, CS, DS, ES and SS points to the same segment, and the actual message is in the code segment.

_TEXT	SEGMENT
	ASSUME CS:_TEXT, DS: _TEXT, ES: _TEXT, SS:_TEXT
	ORG	100H

START:

	mov	ah,09h
	mov	dx, offset msg
	int	21h
	mov	ah,4ch
	int	21h

	msg db "hello world", 0dh,0ah,'$'

_TEXT	ENDS
end	START        

There is one extra step in building the COM file compared to building the EXE. I’m calling masm and link in the same way, but the linker gives a warning that there is no stack segment.

No alt text provided for this image

Building the COM file

That’s where the exe2bin utility comes in, and then the h1.com file is created.

No alt text provided for this image

Building the COM file

So what did I learn?

For me it is important to look back at history in order to learn for the future. Back in the 80’s, memory was expensive and the first PCs had at maximum 640 KB memory. Just a single photo today is at least 10 times bigger than that. So of course it is interesting to reflect about constraints and limitations.

Also, wasn’t it Bill Gates who said?


640K ought to be enough for anyone.
        

This blog post obviously exposes the nerd in me, but I think it is important in my professional life to have the ability to both go deep, but also wide. To see the whole picture, but also the details.

I am by no means an experienced assembler programmer, but I found this to be so fun, so stay tuned for when I explore the 64-bit world(s). My wife asked me about my definition of fun, so I guess we are driven by different things.

More later, and take care!

Tommy Asplund

Technology oriented IT Architect - Digital Workplace

3 年

Thanks for the time travel… a tip check out the Int 10h interupt call for doing graphics in VGA ”mode 13h” that old DOS games used https://en.m.wikipedia.org/wiki/Mode_13h

J?rgen Niesen

IT-Strategist at Stockholms Stadsledningskontor | IT Architect | Chief Integration Officer

3 年

Assembly programming was my best skill in the 1980 th. I did create a disassembler for my Amiga 500 :). Useful when clearing intros for Amiga games. Good luck with the course ??

Thanks for this time travel. Very thought-provoking! Looking forward to the next episode. Maybe VIC-20 will appear ??

回复
Mikael S?derholm

Project manager/enterprise architect with focus on results through teamwork (retired)

3 年

Really interesting read, and my how time flies.

回复
Martin Baker

IT Systems & Project Manager | Scrum Master | SAFe? 6 Agilist | Cloud | eCommerce | Design Thinking | I help companies empower teams to deliver real business value

3 年

Thanks for this little trip down memory lane! ??

回复

要查看或添加评论,请登录

Mats Pettersson的更多文章

  • Reset and reboot

    Reset and reboot

    No, I am not talking about computers now. I'm talking about myself.

    6 条评论
  • Lifelong learning

    Lifelong learning

    I find energy from taking different courses on different universities. Actually it has been without clear direction.

    14 条评论
  • Mid vacation and an IoT summer course

    Mid vacation and an IoT summer course

    Back from a trip to Orkney and Shetland and Stockholm feels very warm and crowded :-) I usually take a university…

    1 条评论
  • Expectations and your destiny

    Expectations and your destiny

    In the qigong teacher training I took some years ago, our teacher often asked - "What are your expectations for the…

  • Silly explorations in assembly language

    Silly explorations in assembly language

    It is funny how some ideas start. In this case, I somehow wondered how parameters are passed between functions in…

    8 条评论
  • Merry Christmas and a Happy New Year

    Merry Christmas and a Happy New Year

    This year I asked ChatGPT to help me writing a short Christmas story about nine santas and a chile pepper Christmas…

    11 条评论
  • IT Development, Architecture + People

    IT Development, Architecture + People

    I've spent two days at our office in Helsinki on-boarding Jan, our new IT Development Manager in Finland. We have been…

    1 条评论
  • Breathe in and breathe out

    Breathe in and breathe out

    The title relates to yoga, which I'm very much influenced by. But this post is not about yoga.

    7 条评论
  • Summer reading - Thinking in bets by Annie Duke

    Summer reading - Thinking in bets by Annie Duke

    I read a great book this summer and want to share some of my impressions. The book is "Thinking in bets - making…

    4 条评论
  • Continuous learning - Foundations of Machine Learning

    Continuous learning - Foundations of Machine Learning

    I've been in the IT business for almost 40 years and it has been a fantastic journey. I am truly grateful to have been…

    6 条评论

社区洞察

其他会员也浏览了