"Don't tell me how hard you work. Tell me how you get done."
- James J. Ling

Invert String

July 30, 2006

; convert small letters to capital AND vice-versa

mov ah,0ah
lea dx,parameter
int 21h

mov ah,02
mov dl,0ah
int 21h
mov dl,0dh
int 21h

; initialize
lea si, input
xor cx, cx
mov cl, [actlen]

; We wish to check if character is a letter
; if yes, capitalize small letters and vice-versa
; if no, copy character

invert:
     mov al, [si]
 
     cmp al, 122
     ja skip

     cmp al, 96
     ja capital

     cmp al, 90
     ja skip

     cmp al, 63
     jb skip

     add al, 32
 
     jmp store

capital:
     sub al, 32

store:
     mov [si], al

skip:
     inc si

loop invert

mov ah, 09
lea dx, input
int 21h

int 20h

parameter label byte
maxlen db 0FF
actlen db ?
input db 0FF dup(’$')

 

Posted by phengpheng at 4:51 pm | permalink | comments[1]

Reverse a string

; reverse string

mov ah,0ah
lea dx,parameter
int 21h

mov ah,02
mov dl,0ah
int 21h
mov dl,0dh
int 21h

; initialize

xor cx, cx             ; zero out cx
lea si, origstring    ; si = inputted string
mov cl, [actlen]     ; cl = length of inputted string
dec cl                   ; since string starts from 0 to cl-1
lea di, revstring     ; di = empty
add di, cx   

reverse:
        mov al, [si]  ; get character
        mov [di], al  ; copy to di at ‘cl-1′th position
        dec di   
        inc si
 
 cmp al, ‘$’           ; means end of string
 jne reverse

mov ah, 09
lea dx, revstring
int 21h

int 20h

parameter label byte
maxlen db 0FF
actlen db ?
origstring db 0FF dup(’$')

revstring db 0FF dup (’$')

Posted by phengpheng at 4:49 pm | permalink | Add comment

Palindrome

July 27, 2006

At last! This head-breaking palindrome program is done…

 ; –ask string from user–
mov ah,0ah
lea dx,parameter
int 21h

mov ah,02
mov dl,0ah
int 21h
mov dl,0dh
int 21h

;–intialize–
mov cx, 0                ; or xor cx, cx –for making cx=0
lea si, namefield      ; load address of namespace
mov cl, [actlen]        ; cl refers to the length of the string
dec cl                      ; strings start at 0 and ends at [actlen]-1
lea di, namefield      ; load address of namespace
add di, cx                ; di now points to the last character of string

mov ah, 09              ; print string function

compare:
 mov cl, [si]             ; get character from si
 mov ch, [di]            ; get character from di
 cmp cl, ch               ; compare two characters
 jne stop                  ; if not equal, not palindrome

 inc si
 dec di   
 
 cmp di, si               ; check if si>di
 jns compare

 lea dx, pal
 int 21h
 jmp exit

stop:
 lea dx, notpal
 int 21h

exit:
 int 20h

 

parameter label byte
maxlen db 0FF
actlen db ?
namefield db 0FF dup(’$')

pal db ‘This string is a palindrome$’
notpal db ‘This string is not a palindrome$’

 

 

Posted by phengpheng at 9:57 pm | permalink | comments[3]

Toupper

July 26, 2006

lea si, msg                  ; ds:si points to message
mov cx, 7                    ; cx holds message length

toupper:
       mov al, [si]          ; al holds current letter      
      
       cmp al, 97          
       jb skip                
      
       cmp al, 122       
       ja skip                       

       sub al, 32            ; capitalize letter
       mov [si], al          ; replace letter
skip:
       inc si                   ; move to next letter
loop    toupper            ; loop 7 times
 
       mov ah, 09          ; print function
       lea dx, MSG         ; load string to be printed
       int 21h                ; call DOS
       int 20h                ; exit to DOS

MSG DB “GraInNe$”      ; define message

 

Posted by phengpheng at 3:59 pm | permalink | comments[1]

JAVA tutorial

July 19, 2006

For a little JAVA tutorial, I made this site for you…

http://www.geocities.com/phengpheng15/index.html 

Posted by phengpheng at 9:08 pm | permalink | Add comment

String concatenation

MSG DB ‘Yap$’
MSG2 DB ‘Grainne$’

MOV CX, 3
LEA si, MSG
LEA di, MSG2

recur:
 
 MOV AL, [si]
 MOV [di], AL
 INC si
 INC di
 DEC CX
 JNZ recur

mov al, ‘$’
MOV AH, 09
LEA DX, MSG2
INT 21H
INT 20H

Another way of doing this code at the same time conscious about memory usage daw[coded by Niel]

MSG DB ‘Yap$’
MSG2 DB ‘Grainne$’

mov cx, 3       ; counter for REP instruction
lea si, MSG     ; string to be copied
lea di, MSG2    ; where to copy
cld             ; clear directrion flag
rep movsb       ; store byte from si to di
mov al, ‘$’      ; the NULL terminator. remember? :D
mov [di], al      ; terminate the new string
mov ah, 09      ; print function
lea dx, MSG2    ; string to be printed
int 21h         ; call DOS
int 20h         ; exit to DOS
I tried opening command rather than cmd for my assembly code, but still I’ve waited for a long time and failed to assemble my code. I was told by Niel that it might be because of other issues, for the code assembled properly in his machine. What other issues it might be, I’ll still know about them. As for now, I was told that the output of my assembly code is ‘Yapinne’. I still need to modify this code, because I intend to display ‘Grainne Yap’. I’ll just keep you posted soon!

 

 

Posted by phengpheng at 8:33 pm | permalink | comments[4]

CS217 class

July 16, 2006

I’m using A86 as my assembler for my assembly codes. Click here to download assembler


1st lesson:  Just a simple “Hello World” display
MSG DB ‘Hello World$’

MOV AH, 09              ; print function
LEA DX, MSG            ; string
INT 21H                      ; call dos
INT 20H                      ; return to dos

2nd lesson: Asking and displaying a number input
xxx:                
            MOV AH, 08              ; keyboard input w/ echo function
            INT 21H                      ; call dos
            CMP AL, 30H             ; compare input with 0
            JB xxx                    
            CMP AL, 39H             ; compare input with 9
            JA xxx                         
            MOV AH, 02              ; display a character function
            MOV DL, AL              ; copy character to DL, and display DL
            INT 21H                      ; call dos
            INT 20H                      ; exit dos

3rd lesson: More on conditions
msg db ‘Hello Guys!$’

here:
mov ah, 01                   ; keyboard input with display function
int 21h                          ; call dos
cmp al, ‘x’                     ; compare input with character ‘x’
je exit                           ; if input is ‘x’, go to exit
cmp al, ‘y’                     ; compare input with character ‘y’
jne here                        ; if not equal to ‘y’, loop
mov ah, 09                   ; if equal,  display function
lea dx, msg                   ; display string ‘Hello Guys!’
int 21h                          ; call dos

exit:
int 20h                          ; exit dos

 

Posted by phengpheng at 2:47 pm | permalink | Add comment

     

July 2006
M T W T F S S
« May   Aug »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Sponsored Links

About Me

A Computer Science graduate who is a fanatic in assembly, java, and j2me programming. Developed BlueVoice system (Direct Voice Communication in Mobile Phones), this system allows mobile users to experience FREE VOICE CALLS

Subscribe

Technorati
Bloglines

Tagboard

phengpheng:

Haven’t managed my blog for a long time already because I’m so busy now… Sorry to cause you guyz trouble…

Jun Mark:

hoW tO creaTE a PrOGram thAT woULD oUTpuT ascii table???

Jun Mark:

pLZ anSwer mY qUEstions

cutieGurl:

how to convert binary to hexadecimal, decimal and octal?????????please. answer me??????????

mary ann:

kuya, ung binary to decimal converter nyo. mali man? ung sa mga compare mo. ung may 0,9,A,F etc… bad character lumalabaspls rep asap po. tnx

carol:

how to convert decimal to binary to octal and hexadecimal

Galwin:

been here!

galwin:

nice site. hope you could visit mine, too.

pathy:

FRIENDS FOREVER!! Miss you na!!!

ridvan:

aus, i seldom see lady programmers. hehe. keep it up. and oh yeah, i guess i saw you during the MICT Quiz Show held in cdo. :)
keep up the codes!

phengpheng:

I miss updating this blog… Sana may time and pc ako to learn new stuffs aside from my work…

support:

Congratulations, you’ve just completed the installation of this shoutbox.

pheng:

uy! you’re here again!

Jay:

Woooohhhh orange…sweat… nakakasilaw! hehe :)

jay:

tagboard flood hehe sensya… had nothing fun to do. :)

pheng:

jaaaaayyyyy….:) ketal man?:)

niel:

no spamming please :p hehehe joke lang jay.

Jay:

Uyyyyyy!!!! Grraaaaaaaiiiinnnneeee
:)
Sssshhhh, el sikret! :)
Niiiiiiiiiiiiieeeeeel
Sup dude!!!!
Paaaaaaaaaaaaaathy
Ketal!?

niel:

ei pheng! :D slick-elegant layout! love it!

yue:

phengpheng!

Leave a message ▼