Thompson MSH(mini-shell)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Thompson MSH(mini-shell)
# 1  
Old 08-14-2015
Reference Thompson MSH(mini-shell)

Hi Guys!

Recently, I disassemble the MSH. And reconstructed. I thought maybe somebody wants to see looked like a second shell. In practice, the most ancient shell. It is written in assembler (AT&T). Owner Ken Thompson, Dennis Ritchie.

Code:
	mov	$parbuf,r1
	mov	$parp,r2
	clr	r3
	jsr	pc,blank
	cmp	r0,$'\n  /
	bne	1f
	sys	exit
1:
	mov	r1,(r2)+
2:
	movb	r0,(r1)+
	jsr	pc,getchar
	cmp	r0,$' / space
	beq	3f
	cmp	r0,$'\n  /
	beq	1f
	br	2b
3:
	clrb	(r1)+
	jsr	pc,blank
	cmp	r0,$'\n  /
	beq	1f
	br	1b
1:
	clr	(r2)+
	tst	r3
	bne	1f
	sys	exec; parbuf; parp /
	sys	exec; binpb; parp /
	br	2f
1:
	mov	$glob,parp
	sys	exec; glob; parp /
2:
	mov	$1,r0	
	sys	write; quest; 2. 
	sys	exit
quest:
	<? >
blank:
	jsr	pc,getchar
	cmp	r0,$' / space
	beq	blank
	rts	pc
getchar:
	clr	r0
	sys	read; chr; 1 / read char
	bcs	xit1
	tst	r0
	beq	xit1
	movb	chr,r0
	cmp	r0,$'? /
	beq	1f
	cmp	r0,$'* /
	beq	1f
	cmp	r0,$'[ /
	bne	2f
1:
	inc	r3
2:
	rts	pc
xit1:
	sys	exit

chr:	.=.+1
glob:
	</etc/glob\0> / globbing
binpb:
	</bin/>
parbuf:	.=.+1000.
parp:		.=.+200.     / real size unknown

Full description in Unix Programmer's Manual, First Edition.
Or here(see below): login(7) - Unix First Edition Manual Page

Last edited by GLbS; 08-14-2015 at 01:08 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

2. Shell Programming and Scripting

Need help in a mini project

Hi All, I want to make something like described below - "Double click on an executable file that will check the health status and other things of various linux servers and send an email to a list of people." I can make shell scripts for individual servers but how to make a script that will check... (1 Reply)
Discussion started by: csrohit
1 Replies

3. UNIX for Dummies Questions & Answers

mini shell programming (help)

Hi All, Well i m a taking an operating system course (newbie to unix) we have studied till now: the fork () execv() the teacher asked us to create a mini shell that execute a user command: cmd1 he said everything in is optional we can use any combination Well dudes , i m really... (2 Replies)
Discussion started by: ELECTRO
2 Replies

4. Programming

Mini Shell in C

Hi Everyone, I am a student learning C and Unix. I want to create a shell in C which accepts command line arguments and executes them. I am not sure how to do this. Any help would be greatly appreciated. Thanks (5 Replies)
Discussion started by: passat
5 Replies
Login or Register to Ask a Question