Skip to content

Instantly share code, notes, and snippets.

@aleks-mariusz
Last active August 29, 2015 14:00
Show Gist options
  • Save aleks-mariusz/c3056c0fe49c4f485e65 to your computer and use it in GitHub Desktop.
Save aleks-mariusz/c3056c0fe49c4f485e65 to your computer and use it in GitHub Desktop.
Feb 28 2000 - ASSGN2.ASM - This was an assignment from a course i took in assembly at the turn of the century.. Pretty basic stuff (as far as x86 asm goes).. Sadly I haven't done much with assembler since then other than the occasional software crack here and there..
title Course Assignment 2 for cs205 (assgn2.asm)
; Alex Koralewski
; id# 0019480
; This program encrypts a string based on predefined rules
;
.model small ; allocate 64k max for code seg & 64k for data seg
.stack 10h ; allocate 16 bytes for stack seg
.data
MYNAME db "alexzz",'$' ; name & pad, valid string
NAME_L = ($ - MYNAME) ; calculate length macro
digit db ?
prompt1 db "Enter a postive, non-zero integer, for encoding: ",'$'
prompt2 db "Encrypted string: ",'$'
prompt3 db "Enter a postive, non-zero integer, for decoding: ",'$'
prompt4 db "Decrypted string: ",'$'
; macros for ease of reading
CR equ 0dh ; carriage return
LF equ 0ah ; line feed
.code
main proc
mov ax,@data ; load data seg addy into
mov ds,ax ; the data seg register
mov ah,9 ; load func 9 (print string)
mov dx,offset prompt1
int 21h
mov ah,1 ; load function 1 (get input)
int 21h ; pause (for user input)
mov digit,al ; save the ascii input
sub digit,30h ; convert ascii -> actual n
mov al,digit ; load n into low ax register
sub MYNAME,al ; MYNAME[0] - n
xor MYNAME+1,00100000b ; toggle case of MYNAME[1]
add MYNAME+2,al ; MYNAME[2] + n
xor MYNAME+3,00100000b ; toggle case of MYNAME[3]
sub MYNAME+4,al ; MYNAME[4] - n
xor MYNAME+5,00100000b ; toggle case of MYNAME[5]
mov al,MYNAME ; swap MYNAME[0] and MYNAME[1]
xchg MYNAME+1,al
mov MYNAME,al
mov al,MYNAME+2 ; swap MYNAME[2] and MYNAME[3]
xchg MYNAME+3,al
mov MYNAME+2,al
mov al,MYNAME+4 ; swap MYNAME[4] and MYNAME[5]
xchg MYNAME+5,al
mov MYNAME+4,al
mov ah,2
mov dl,LF
int 21h
mov dl,CR
int 21h
mov ah,9 ; load func 9 (print string)
mov dx,offset prompt2
int 21h
mov dx,offset MYNAME
int 21h
mov ah,2
mov dl,LF ; load LF char to display
int 21h ; display a line feed
mov dl,CR ; load CR char to display
int 21h ; display a carriage return
mov ah,9
mov dx,offset prompt3
int 21h
mov ah,1 ; load function 1 (get input)
int 21h ; pause (for user input)
mov digit,al ; save the ascii input
sub digit,30h ; convert ascii -> actual n
mov al,MYNAME ; swap MYNAME[0] and MYNAME[1]
xchg MYNAME+1,al
mov MYNAME,al
mov al,MYNAME+2 ; swap MYNAME[2] and MYNAME[3]
xchg MYNAME+3,al
mov MYNAME+2,al
mov al,MYNAME+4 ; swap MYNAME[4] and MYNAME[5]
xchg MYNAME+5,al
mov MYNAME+4,al
mov al,digit ; load n into low ax register
add MYNAME,al ; MYNAME[0] + n
xor MYNAME+1,00100000b ; toggle case of MYNAME[1]
sub MYNAME+2,al ; MYNAME[2] - n
xor MYNAME+3,00100000b ; toggle case of MYNAME[3]
add MYNAME+4,al ; MYNAME[4] + n
xor MYNAME+5,00100000b ; toggle case of MYNAME[5]
mov ah,2
mov dl,LF
int 21h
mov dl,CR
int 21h
mov ah,9 ; load func 9 (print string)
mov dx,offset prompt4
int 21h
mov dx,offset MYNAME
int 21h
mov ah,2
mov dl,LF
int 21h
mov dl,CR
int 21h
mov ah,1 ; load function 1 (get input)
int 21h ; pause (for user input)
mov ax,4c00h ; load function 4Ch (exit)
int 21h ; end program
main endp
end main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment