Advertising (This ad goes away for registered users. You can Login or Register)

[Tutorial] Introduction to programming using C (VIII)

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
wth
HBL Developer
Posts: 834
Joined: Wed Aug 31, 2011 4:44 pm
Contact:

Re: [Tutorial] Introduction to programming using C (VIII)

Post by wth » Fri Mar 29, 2013 8:27 pm

m0skit0 wrote:Write a program that checks if one string is part of another (if it's a substring).
Write the same program without using any loop construct (for, while, etc...) :mrgreen:
seriously ? guess I'm clueless there after 2s thinking lol
Advertising

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: [Tutorial] Introduction to programming using C (VIII)

Post by Acid_Snake » Fri Mar 29, 2013 11:22 pm

wth wrote: seriously ? guess I'm clueless there after 2s thinking lol
2s thinking? your a god! I wouldn't have lasted half a second :o
Advertising

wth
HBL Developer
Posts: 834
Joined: Wed Aug 31, 2011 4:44 pm
Contact:

Re: [Tutorial] Introduction to programming using C (VIII)

Post by wth » Sat Mar 30, 2013 1:45 pm

indeed pretty pointless trying such impossible thing imho xD

wololo
Site Admin
Posts: 3619
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: [Tutorial] Introduction to programming using C (VIII)

Post by wololo » Sun Mar 31, 2013 4:21 am

wth wrote:indeed pretty pointless trying such impossible thing imho xD
You can do it recursively. Not impossible at all.
If you need US PSN Codes, this technique is what I recommend.

Looking for guest bloggers and news hunters here at wololo.net, PM me!

wth
HBL Developer
Posts: 834
Joined: Wed Aug 31, 2011 4:44 pm
Contact:

Re: [Tutorial] Introduction to programming using C (VIII)

Post by wth » Sun Mar 31, 2013 6:17 pm

ah right didn't think about that, was thinking we had to do it with bare instructions forgetting we can loop without loops lol
without recusivity too impossible though :mrgreen: xD

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: [Tutorial] Introduction to programming using C (VIII)

Post by Acid_Snake » Mon Apr 01, 2013 10:45 am

lol forgot about recursivity, I don't use it as a replacement for loop constructs too much, mostly use it to refresh something (i.e. a file browser in which the user has changed directory)

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: [Tutorial] Introduction to programming using C (VIII)

Post by m0skit0 » Fri Apr 05, 2013 9:25 pm

All I see is too much talking and no code :lol: ;)
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: [Tutorial] Introduction to programming using C (VIII)

Post by Acid_Snake » Fri Apr 05, 2013 10:25 pm

m0skit0 wrote:All I see is too much talking and no code :lol: ;)
here you go bruh, code:

Code: Select all

; multi-segment executable file template.

data segment
    ; add your data here!
    msj_pedirCadena DB "Introduzca una cadena:$"
    msj_resultado DB "La cadena resultante es:$"
    saltoLinea DB 10, 13, '$'
    cadenaL DB 23 DUP(?)
    cadenaR DB 41 DUP(?)

ends

stack segment
    dw   128  dup(0)
ends

code segment       
    
;en el registro DX se encuentra la dirección de la cadena a imprimir
Imprimir PROC
    push ax
    mov ah, 9
    int 21h
    pop ax
    ret
Imprimir ENDP

;en el registro DX se encuentra la dirección de la cadena donde se
;almacenará el resultado de la lectura por teclado
LeerCadena PROC
    push ax
    mov ah, 0ah
    int 21h
    pop ax
    ret
LeerCadena ENDP
              
              
SepararCaracteres PROC
    push ax
    push cx
    push si
    push di
    mov si, 2
    mov di, 0
    mov cl, cadenaL[1]
    mov ch, 0
    mov si, cx
    inc si
    cmp cx, 0
    je finSepararCaracteres
bSepararCaracteres:
    mov al, cadenaL[si]
    mov cadenaR[di], al
    inc di
    dec si
    loop bSepararCaracteres
finSepararCaracteres:
    mov cadenaR[di], '$'
    pop di
    pop si
    pop cx
    pop ax
    ret
SepararCaracteres ENDP


start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

    ; add your code here
    lea dx, msj_pedirCadena
    call Imprimir
    lea dx, saltoLinea
    call Imprimir
    lea dx, cadenaL
    mov cadenaL[0], 21
    call LeerCadena
    lea dx, saltoLinea
    call Imprimir
    call SepararCaracteres
    lea dx, msj_resultado
    call Imprimir
    lea dx, saltoLinea
    call Imprimir
    lea dx, cadenaR
    call Imprimir

    
    ; wait for any key....    
    mov ah, 1
    int 21h
    
    mov ax, 4c00h ; exit to operating system.
    int 21h    
ends

end start ; set entry point and stop the assembler.

Post Reply

Return to “Programming and Security”